]> granicus.if.org Git - libevent/commitdiff
Fix EV_CLOSED detection/reporting (epoll only)
authorAzat Khuzhin <azat@libevent.org>
Mon, 4 May 2020 21:21:18 +0000 (00:21 +0300)
committerAzat Khuzhin <azat@libevent.org>
Mon, 4 May 2020 21:25:23 +0000 (00:25 +0300)
- 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: #984
epoll.c
test/regress.c

diff --git a/epoll.c b/epoll.c
index 299e3d355ce85e3d7d5c559f6b1e6673ff128edb..4b1e3963d1e059d972f6ad1f555d1390205db0ad 100644 (file)
--- a/epoll.c
+++ b/epoll.c
@@ -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)
index 53c07183196032c3125c1e8ae39341f4c8126ba4..fe2a8fd1e1acaf741b68615dc35bb2857eddac1c 100644 (file)
@@ -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)