Skip to content

Commit

Permalink
Merge pull request #46 from Allenxuxu/fix-kqueue
Browse files Browse the repository at this point in the history
fix kqueue
  • Loading branch information
Allenxuxu authored Nov 6, 2020
2 parents d614f29 + e40ed6e commit d13351d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions poller/kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ func (p *Poller) EnableRead(fd int) error {
func (p *Poller) kEvents(old Event, new Event, fd int) (ret []unix.Kevent_t) {
if new&EventRead != 0 {
if old&EventRead == 0 {
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_ADD, Filter: unix.EVFILT_READ})
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_ADD | unix.EV_ENABLE, Filter: unix.EVFILT_READ})
}
} else {
if old&EventRead != 0 {
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_DELETE, Filter: unix.EVFILT_READ})
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_DELETE | unix.EV_ONESHOT, Filter: unix.EVFILT_READ})
}
}

if new&EventWrite != 0 {
if old&EventWrite == 0 {
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_ADD, Filter: unix.EVFILT_WRITE})
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_ADD | unix.EV_ENABLE, Filter: unix.EVFILT_WRITE})
}
} else {
if old&EventWrite != 0 {
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_DELETE, Filter: unix.EVFILT_WRITE})
ret = append(ret, unix.Kevent_t{Ident: uint64(fd), Flags: unix.EV_DELETE | unix.EV_ONESHOT, Filter: unix.EVFILT_WRITE})
}
}
return
Expand Down Expand Up @@ -168,10 +168,10 @@ func (p *Poller) Poll(handler func(fd int, event Event)) {
if (events[i].Flags&unix.EV_ERROR != 0) || (events[i].Flags&unix.EV_EOF != 0) {
rEvents |= EventErr
}
if events[i].Filter == unix.EVFILT_WRITE {
if events[i].Filter == unix.EVFILT_WRITE && events[i].Flags&unix.EV_ENABLE != 0 {
rEvents |= EventWrite
}
if events[i].Filter == unix.EVFILT_READ {
if events[i].Filter == unix.EVFILT_READ && events[i].Flags&unix.EV_ENABLE != 0 {
rEvents |= EventRead
}

Expand Down

0 comments on commit d13351d

Please sign in to comment.