Skip to content

Commit

Permalink
poll: Prevent libevent from spinning if POLLNVAL occurs
Browse files Browse the repository at this point in the history
This can happen, for example if libevent is being used to poll fds given
by another library where the other library closes the fds without
notifying the program using it that said fds were closed. In this case,
libevent will simply spin on poll() since there are active fds, but
won't call any event callback to handle the condition.

In epoll case after socket closed it automatically removed from epfd, so
IOW it will not spin in epoll* API, just a timeout.

Fixes: libevent#379
  • Loading branch information
thentenaar authored and azat committed Nov 4, 2016
1 parent 9ac000c commit 675974c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv)
res = 0;

/* If the file gets closed notify */
if (what & (POLLHUP|POLLERR))
if (what & (POLLHUP|POLLERR|POLLNVAL))
what |= POLLIN|POLLOUT;
if (what & POLLIN)
res |= EV_READ;
Expand Down

0 comments on commit 675974c

Please sign in to comment.