Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pilot committed Oct 16, 2023
1 parent 56ccc6b commit 7806448
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
11 changes: 5 additions & 6 deletions epoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ type poll struct {
}

func openPoll() (*poll, error) {
ep := new(poll)
fd, err := syscall.EpollCreate1(0)
if err != nil {
return nil, err
}

return &poll{
fd: fd,
fdEvents: make(map[int]*fdEvent),
events: make([]syscall.EpollEvent, initialNEvent),
}, nil
ep.fd = fd
ep.fdEvents = make(map[int]*fdEvent, initialNEvent)
ep.events = make([]syscall.EpollEvent, initialNEvent)
return ep, nil
}

func (ep *poll) add(ev *Event) error {
Expand Down
2 changes: 1 addition & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (bs *EventBase) handleActiveEvents() {
for e := bs.activeEvLists[i].front(); e != nil; {
next := e.nextEle()
ev := e.value
e = next
if ev.events&EvPersist != 0 {
bs.eventQueueRemove(ev, evListActive)
if ev.events&EvTimeout != 0 {
Expand All @@ -285,7 +286,6 @@ func (bs *EventBase) handleActiveEvents() {
} else {
bs.delEvent(ev)
}
e = next
ev.cb(ev.fd, ev.res, ev.arg)
}
}
Expand Down
11 changes: 5 additions & 6 deletions kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ type poll struct {
}

func openPoll() (*poll, error) {
kq := new(poll)
fd, err := syscall.Kqueue()
if err != nil {
return nil, err
}

return &poll{
fd: fd,
changes: make([]syscall.Kevent_t, initialNEvent),
events: make([]syscall.Kevent_t, initialNEvent),
}, nil
kq.fd = fd
kq.changes = make([]syscall.Kevent_t, initialNEvent)
kq.events = make([]syscall.Kevent_t, initialNEvent)
return kq, nil
}

func (kq *poll) add(ev *Event) error {
Expand Down

0 comments on commit 7806448

Please sign in to comment.