From 1afee1ca0739c25a459367f852a68054ddb5df67 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 29 May 2025 02:58:16 +0300 Subject: [PATCH] netpoll: report shutdown sockets as POLLIN|POLLOUT --- src/netpoll.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/netpoll.cpp b/src/netpoll.cpp index c2e98dc..c282c6a 100644 --- a/src/netpoll.cpp +++ b/src/netpoll.cpp @@ -71,7 +71,7 @@ int get(struct net_pollfd *out) #define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member))) struct polldata { uv_poll_t uv; - int events, revents, fd; + int events, revents, fd, dead; }; static polldata *uvpoll[NETPOLL_MAXFDS] = {}; static uv_loop_t *uvloop = 0; @@ -116,6 +116,7 @@ static void add_impl(int i) poll->events = 0; poll->revents = 0; poll->fd = fds[i].fd; + poll->dead = 0; uv_poll_init_socket(uvloop, &poll->uv, fds[i].fd); if (lastptr >= i) lastptr++; @@ -141,7 +142,8 @@ static void cb(uv_poll_t *handle, int status, int events) uv_poll_stop(handle); if (status == -EBADF) { fprintf(stderr, "netpoll::cb: %d EBADF!\n", poll->fd); - del_and_close(poll->fd); + poll->dead = 1; + poll->revents = poll->events & (UV_READABLE | UV_WRITABLE); } lastptr = 0; } @@ -157,8 +159,12 @@ static void reg_impl(int i, int ev) int begin(void) { for (int i = 0; i < nfds; i++) { - uv_poll_start(&uvpoll[i]->uv, uvpoll[i]->events, cb); - uvpoll[i]->revents = 0; + if (uvpoll[i]->dead == 0) { + uv_poll_start(&uvpoll[i]->uv, uvpoll[i]->events, cb); + uvpoll[i]->revents = 0; + } else { + uvpoll[i]->revents = uvpoll[i]->events & (UV_READABLE | UV_WRITABLE); + } } uv_run(uvloop, UV_RUN_ONCE); return 0; -- 2.56.0