Skip to content

Commit

Permalink
fix timeout event duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng-zhongliang committed Oct 5, 2023
1 parent fdacff0 commit 4a830c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,16 @@ func (bs *EventBase) handleActiveEvents() {
ev := e.value.(*Event)
if ev.events&EvPersist != 0 {
bs.eventQueueRemove(ev, evListActive)
bs.eventQueueRemove(ev, evListTimeout)
if ev.events&EvTimeout != 0 {
bs.eventQueueRemove(ev, evListTimeout)
ev.deadline = bs.now().Add(ev.timeout)
bs.eventQueueInsert(ev, evListTimeout)
}
} else {
bs.delEvent(ev)
}
e = next

if ev.events&EvTimeout != 0 && ev.events&EvPersist != 0 {
ev.deadline = bs.now().Add(ev.timeout)
bs.eventQueueInsert(ev, evListTimeout)
}

ev.cb(ev.fd, ev.res, ev.arg)
}
}
Expand Down
6 changes: 3 additions & 3 deletions kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func (kq *poller) polling(cb func(ev *Event, res uint32), timeout time.Duration)
for i := 0; i < n; i++ {
flags := kq.events[i].Flags
if flags&syscall.EV_ERROR != 0 {
data := syscall.Errno(kq.events[i].Data)
if data&(syscall.EBADF|syscall.ENOENT|syscall.EINVAL) != 0 {
errno := syscall.Errno(kq.events[i].Data)
if errno&(syscall.EBADF|syscall.ENOENT|syscall.EINVAL) != 0 {
continue
}
return data
return errno
}

which := uint32(0)
Expand Down

0 comments on commit 4a830c2

Please sign in to comment.