From: Egor Date: Sun, 2 Mar 2025 20:05:25 +0000 (+0200) Subject: netpoll: add ability to change type without readding X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=c9c6c369adf0c4cb5720f92104188ecbe06d5993;p=patchyircd.git netpoll: add ability to change type without readding kinda fixes an assert in libuv, but not really --- diff --git a/src/net.cpp b/src/net.cpp index 135a91d..78d0fab 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -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()) diff --git a/src/netpoll.cpp b/src/netpoll.cpp index 13a0dc6..e50ca78 100644 --- a/src/netpoll.cpp +++ b/src/netpoll.cpp @@ -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; +} diff --git a/src/netpoll.h b/src/netpoll.h index 46346ff..4a92d44 100644 --- a/src/netpoll.h +++ b/src/netpoll.h @@ -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