From 20ff819fc032fb6ae902022f12891ae7c9f73151 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Fri, 25 Oct 2024 22:06:23 -0600 Subject: gnet: Set SO_REUSEPORT This is necessary for the multiple-listener-ports thing. --- cmd/srv9p/gnet.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/srv9p/gnet.c b/cmd/srv9p/gnet.c index 5dd4a93..39ad9b2 100644 --- a/cmd/srv9p/gnet.c +++ b/cmd/srv9p/gnet.c @@ -14,7 +14,7 @@ /* net */ #include /* for htons(3p) */ #include /* for struct sockaddr_in */ -#include /* for struct sockaddr, socket(), SOCK_* flags, setsockopt(), SOL_SOCKET, SO_REUSEADDR, bind(), listen(), accept() */ +#include /* for struct sockaddr{,_storage}, SOCK_*, SOL_*, SO_*, socket(), setsockopt(), bind(), listen(), accept() */ /* async */ #include /* for pthread_* */ #include /* for siginfo_t, struct sigaction, enum sigval, sigaction(), SIGRTMIN, SIGRTMAX, SA_SIGINFO */ @@ -113,11 +113,13 @@ void gnet_tcp_listener_init(struct gnet_tcp_listener *self, uint16_t port) { if (listenerfd < 0) error(1, errno, "socket"); if (setsockopt(listenerfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0) - error(1, errno, "setsockopt"); + error(1, errno, "setsockopt(fd=%d, SO_REUSEADDR=1)", listenerfd); + if (setsockopt(listenerfd, SOL_SOCKET, SO_REUSEPORT, &(int){1}, sizeof(int)) < 0) + error(1, errno, "setsockopt(fd=%d, SO_REUSEPORT=1)", listenerfd); if (bind(listenerfd, &addr.gen, sizeof addr) < 0) - error(1, errno, "bind"); + error(1, errno, "bind(fd=%d)", listenerfd); if (listen(listenerfd, 0) < 0) - error(1, errno, "listen"); + error(1, errno, "listen(fd=%d)", listenerfd); self->vtable = &gnet_tcp_listener_vtable; self->fd = listenerfd; -- cgit v1.2.3-2-g168b