Skip to content

Commit

Permalink
Fix EV_CLOSED detection/reporting (epoll only)
Browse files Browse the repository at this point in the history
- EV_CLOSED is EPOLLRDHUP in epoll
- EPOLLRDHUP reported w/o EPOLLHUP if the socket closed with shutdown(SHUT_WR)
- EPOLLRDHUP reported w/  EPOLLHUP if the socket closed with close()
  so in this case epoll backend will detect this event as error
  (EV_READ|EV_WRITE), since the epoll_ctl() will return EPOLLRDHUP with
  EPOLLHUP set, but this is not correct, let's fix this.

Fixes: libevent#984
  • Loading branch information
azat committed May 4, 2020
1 parent c10cde4 commit 972b456
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 3 additions & 1 deletion epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ epoll_dispatch(struct event_base *base, struct timeval *tv)
continue;
#endif

if (what & (EPOLLHUP|EPOLLERR)) {
if (what & EPOLLERR) {
ev = EV_READ | EV_WRITE;
} else if ((what & EPOLLHUP) && !(what & EPOLLRDHUP)) {
ev = EV_READ | EV_WRITE;
} else {
if (what & EPOLLIN)
Expand Down
9 changes: 2 additions & 7 deletions test/regress.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,8 @@ test_simpleclose(void *ptr)
tt_assert(!event_base_loopexit(base, &tv));
}

/* via close() */
if (pair[1] == -1) {
tt_int_op(event_base_loop(base, EVLOOP_NONBLOCK), ==, 0);
} else {
tt_int_op(event_base_loop(base, EVLOOP_NONBLOCK), ==, !persist);
tt_int_op(got_event, ==, (events & ~EV_PERSIST));
}
tt_int_op(event_base_loop(base, EVLOOP_NONBLOCK), ==, !persist);
tt_int_op(got_event, ==, (events & ~EV_PERSIST));

end:
if (ev)
Expand Down

0 comments on commit 972b456

Please sign in to comment.