]> PatchyGit - patchyircd.git/commitdiff
netpoll: report shutdown sockets as POLLIN|POLLOUT
authorEgor <egor@patchysicp.xyz>
Wed, 28 May 2025 23:58:16 +0000 (02:58 +0300)
committerEgor <egor@patchysicp.xyz>
Wed, 28 May 2025 23:58:16 +0000 (02:58 +0300)
src/netpoll.cpp

index c2e98dc..c282c6a 100644 (file)
@@ -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;