Skip to content

Commit

Permalink
kqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng-zhongliang committed Oct 2, 2023
1 parent c113e58 commit 4ffc7b4
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,37 +195,6 @@ func NewBase() (*EventBase, error) {
}, nil
}

// addEvent adds an event to the event base.
func (bs *EventBase) addEvent(ev *Event) error {
if ev.events&EvTimeout != 0 {
ev.deadline = bs.now().Add(ev.timeout)
bs.eventQueueInsert(ev, evListTimeout)
}

bs.eventQueueInsert(ev, evListInserted)

if ev.events&(EvRead|EvWrite|EvClosed) != 0 {
return bs.poller.add(ev)
}

return nil
}

// delEvent deletes an event from the event base.
func (bs *EventBase) delEvent(ev *Event) error {
bs.eventQueueRemove(ev, evListTimeout)

bs.eventQueueRemove(ev, evListActive)

bs.eventQueueRemove(ev, evListInserted)

if ev.events&(EvRead|EvWrite|EvClosed) != 0 {
return bs.poller.del(ev)
}

return nil
}

// Loop loops events.
// If flags is EvLoopOnce, it will block until an event is triggered. Then it will exit.
// If flags is EvLoopNoblock, it will not block.
Expand Down Expand Up @@ -261,6 +230,37 @@ func (bs *EventBase) Exit() error {
return bs.poller.close()
}

// addEvent adds an event to the event base.
func (bs *EventBase) addEvent(ev *Event) error {
if ev.events&EvTimeout != 0 {
ev.deadline = bs.now().Add(ev.timeout)
bs.eventQueueInsert(ev, evListTimeout)
}

bs.eventQueueInsert(ev, evListInserted)

if ev.events&(EvRead|EvWrite|EvClosed) != 0 {
return bs.poller.add(ev)
}

return nil
}

// delEvent deletes an event from the event base.
func (bs *EventBase) delEvent(ev *Event) error {
bs.eventQueueRemove(ev, evListTimeout)

bs.eventQueueRemove(ev, evListActive)

bs.eventQueueRemove(ev, evListInserted)

if ev.events&(EvRead|EvWrite|EvClosed) != 0 {
return bs.poller.del(ev)
}

return nil
}

func (bs *EventBase) waitTime(noblock bool) time.Duration {
if noblock {
return 0
Expand Down

0 comments on commit 4ffc7b4

Please sign in to comment.