diff --git a/poller/kqueue.go b/poller/kqueue.go index 6c3b485..36dcbce 100644 --- a/poller/kqueue.go +++ b/poller/kqueue.go @@ -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 @@ -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 }