Skip to content

Commit

Permalink
kqueue: fix err judge, use edge-triggered mode (EV_CLEAR)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Jan 19, 2024
1 parent 69dfa3c commit 9c95743
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions poller_kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,23 @@ func (p *poller) trigger() {
func (p *poller) addRead(fd int) {
p.mux.Lock()
p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_READ})
p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE})
p.mux.Unlock()
p.trigger()
}

func (p *poller) resetRead(fd int) {
p.mux.Lock()
p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_DELETE, Filter: syscall.EVFILT_WRITE})
p.mux.Unlock()
p.trigger()
// p.mux.Lock()
// p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_DELETE, Filter: syscall.EVFILT_WRITE})
// p.mux.Unlock()
// p.trigger()
}

func (p *poller) modWrite(fd int) {
p.mux.Lock()
p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE})
p.mux.Unlock()
p.trigger()
// p.mux.Lock()
// p.eventList = append(p.eventList, syscall.Kevent_t{Ident: uint64(fd), Flags: syscall.EV_ADD, Filter: syscall.EVFILT_WRITE})
// p.mux.Unlock()
// p.trigger()
}

func (p *poller) deleteEvent(fd int) {
Expand Down Expand Up @@ -243,7 +244,7 @@ func (p *poller) readWriteLoop() {
p.eventList = nil
p.mux.Unlock()
n, err := syscall.Kevent(p.kfd, changes, events, nil)
if err != nil && errors.Is(err, syscall.EINTR) {
if err != nil && !errors.Is(err, syscall.EINTR) {
return
}

Expand Down

0 comments on commit 9c95743

Please sign in to comment.