github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/net/reactor_linux.go (about) 1 // +build linux 2 3 package net 4 5 import "github.com/angenalZZZ/gofunc/net/internal/netpoll" 6 7 func (svr *server) activateMainReactor() { 8 defer svr.signalShutdown() 9 10 svr.logger.Printf("main reactor exits with error:%v\n", svr.mainLoop.poller.Polling(func(fd int, ev uint32) error { 11 return svr.acceptNewConnection(fd) 12 })) 13 } 14 15 func (svr *server) activateSubReactor(el *eventloop) { 16 defer func() { 17 el.closeAllConns() 18 if el.idx == 0 && svr.opts.Ticker { 19 close(svr.ticktock) 20 } 21 svr.signalShutdown() 22 }() 23 24 if el.idx == 0 && svr.opts.Ticker { 25 go el.loopTicker() 26 } 27 28 svr.logger.Printf("event-loop:%d exits with error:%v\n", el.idx, el.poller.Polling(func(fd int, ev uint32) error { 29 if c, ack := el.connections[fd]; ack { 30 switch c.outboundBuffer.IsEmpty() { 31 // Don't change the ordering of processing EPOLLOUT | EPOLLRDHUP / EPOLLIN unless you're 100% 32 // sure what you're doing! 33 // Re-ordering can easily introduce bugs and bad side-effects, as I found out painfully in the past. 34 case false: 35 if ev&netpoll.OutEvents != 0 { 36 return el.loopWrite(c) 37 } 38 return nil 39 case true: 40 if ev&netpoll.InEvents != 0 { 41 return el.loopRead(c) 42 } 43 return nil 44 } 45 } 46 return nil 47 })) 48 }