github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/net/loop_bsd.go (about)

     1  // +build darwin netbsd freebsd openbsd dragonfly
     2  
     3  package net
     4  
     5  import "github.com/angenalZZZ/gofunc/net/internal/netpoll"
     6  
     7  func (el *eventloop) handleEvent(fd int, filter int16) error {
     8  	if c, ok := el.connections[fd]; ok {
     9  		if filter == netpoll.EVFilterSock {
    10  			return el.loopCloseConn(c, nil)
    11  		}
    12  		switch c.outboundBuffer.IsEmpty() {
    13  		// Don't change the ordering of processing EVFILT_WRITE | EVFILT_READ | EV_ERROR/EV_EOF unless you're 100%
    14  		// sure what you're doing!
    15  		// Re-ordering can easily introduce bugs and bad side-effects, as I found out painfully in the past.
    16  		case false:
    17  			if filter == netpoll.EVFilterWrite {
    18  				return el.loopWrite(c)
    19  			}
    20  			return nil
    21  		case true:
    22  			if filter == netpoll.EVFilterRead {
    23  				return el.loopRead(c)
    24  			}
    25  			return nil
    26  		}
    27  	}
    28  	return el.loopAccept(fd)
    29  }