Skip to content

Commit

Permalink
cleanup: refine code and add commentsx
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Feb 3, 2021
1 parent 0f08c8f commit 4ecbc50
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions eventloop_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ func (el *eventloop) loopOpen(c *conn) error {
}

func (el *eventloop) loopRead(c *conn) error {
// If there is pending data in outbound buffer, then we should omit this readable event
// and prioritize the writable events to achieve a higher performance.
if !c.outboundBuffer.IsEmpty() {
return nil
}

n, err := unix.Read(c.fd, el.packet)
if n == 0 || err != nil {
if err == unix.EAGAIN {
Expand Down
2 changes: 1 addition & 1 deletion loop_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (el *eventloop) handleEvent(fd int, ev uint32) error {
return err
}
}
if ev&netpoll.InEvents != 0 && c.outboundBuffer.IsEmpty() {
if ev&netpoll.InEvents != 0 {
return el.loopRead(c)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion reactor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (svr *server) activateSubReactor(el *eventloop, lockOSThread bool) {
return err
}
}
if ev&netpoll.InEvents != 0 && c.outboundBuffer.IsEmpty() {
if ev&netpoll.InEvents != 0 {
return el.loopRead(c)
}
}
Expand Down

0 comments on commit 4ecbc50

Please sign in to comment.