summaryrefslogtreecommitdiff
path: root/cmd/srv9p/gnet.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-25 22:06:23 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-25 22:07:01 -0600
commit20ff819fc032fb6ae902022f12891ae7c9f73151 (patch)
tree66f3c53119d5f0ac5037dfee359029cc356f313b /cmd/srv9p/gnet.c
parent7c03983529f6502206cd40692c794b7c6605d9bf (diff)
gnet: Set SO_REUSEPORT
This is necessary for the multiple-listener-ports thing.
Diffstat (limited to 'cmd/srv9p/gnet.c')
-rw-r--r--cmd/srv9p/gnet.c10
1 files 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 <arpa/inet.h> /* for htons(3p) */
#include <netinet/in.h> /* for struct sockaddr_in */
-#include <sys/socket.h> /* for struct sockaddr, socket(), SOCK_* flags, setsockopt(), SOL_SOCKET, SO_REUSEADDR, bind(), listen(), accept() */
+#include <sys/socket.h> /* for struct sockaddr{,_storage}, SOCK_*, SOL_*, SO_*, socket(), setsockopt(), bind(), listen(), accept() */
/* async */
#include <pthread.h> /* for pthread_* */
#include <signal.h> /* 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;