Skip to content

Commit

Permalink
Always re-register epoll descriptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 16, 2023
1 parent 54b8352 commit 2610960
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ext/io/event/selector/epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ int events_from_epoll_flags(uint32_t flags)
inline static
int IO_Event_Selector_EPoll_Descriptor_update(struct IO_Event_Selector_EPoll *selector, int descriptor, struct IO_Event_Selector_EPoll_Descriptor *epoll_descriptor)
{
if (epoll_descriptor->registered_events == epoll_descriptor->waiting_events) {
// All the events we are interested in are already registered.
return 0;
}
// if (epoll_descriptor->registered_events == epoll_descriptor->waiting_events) {
// // All the events we are interested in are already registered.
// return 0;
// }

if (epoll_descriptor->waiting_events == 0) {
// We are no longer interested in any events.
int result = epoll_ctl(selector->descriptor, EPOLL_CTL_DEL, descriptor, NULL);
if (result == -1) return -1;
// if (result == -1) return -1;

epoll_descriptor->registered_events = 0;

Expand All @@ -197,7 +197,15 @@ int IO_Event_Selector_EPoll_Descriptor_update(struct IO_Event_Selector_EPoll *se
}

int result = epoll_ctl(selector->descriptor, operation, descriptor, &event);
if (result == -1) return -1;
if (result == -1) {
if (errno == ENOENT) {
result = epoll_ctl(selector->descriptor, EPOLL_CTL_ADD, descriptor, &event);
}

if (result == -1) {
return -1;
}
}

epoll_descriptor->registered_events = epoll_descriptor->waiting_events;

Expand Down

0 comments on commit 2610960

Please sign in to comment.