]> PatchyGit - patchyircd.git/commitdiff
netpoll: add ability to change type without readding
authorEgor <egor@patchysicp.xyz>
Sun, 2 Mar 2025 20:05:25 +0000 (22:05 +0200)
committerEgor <egor@patchysicp.xyz>
Sun, 2 Mar 2025 20:05:25 +0000 (22:05 +0200)
kinda fixes an assert in libuv, but not really

src/net.cpp
src/netpoll.cpp
src/netpoll.h

index 135a91d..78d0fab 100644 (file)
@@ -60,10 +60,8 @@ void killConnection(struct client_data *cl, int byChoice)
        }
        cl->next = dyingclients;
        dyingclients = cl;
-       if (cl->FD != INVALID_SOCKET) {
-               net_poll_del(cl->FD);
-               net_poll_add(cl->FD, SOCKTYPE_DYING, cl);
-       }
+       if (cl->FD != INVALID_SOCKET)
+               net_poll_change_type(cl->FD, SOCKTYPE_DYING);
        update_poll_reg(cl);
        /* Part all channels */
        for (auto chan : cl->channels.pop_view())
index 13a0dc6..e50ca78 100644 (file)
@@ -381,3 +381,16 @@ void net_poll_reg(SOCKET fd, int ev)
        }
        net_poll_reg_impl(i, ev);
 }
+void net_poll_change_type(SOCKET fd, int type)
+{
+       if (fd == INVALID_SOCKET) {
+               fprintf(stderr, "net_poll_change_type: INVALID_SOCKET\n");
+               abort();
+       }
+       int i = search(fd);
+       if (!IS_FOUND(i, fd)) {
+               fprintf(stderr, "net_poll_change_type: socket not added\n");
+               abort();
+       }
+       fds[i].type = type;
+}
index 46346ff..4a92d44 100644 (file)
@@ -11,6 +11,7 @@ void net_poll_fini(void);
 void net_poll_add(SOCKET fd, int type, void *assoc);
 void net_poll_del(SOCKET fd);
 void net_poll_reg(SOCKET fd, int ev);
+void net_poll_change_type(SOCKET fd, int type);
 int net_poll_begin(void);
 int net_poll_get(struct net_pollfd *out);
 #define NETPOLL_IN 1