diff options
-rw-r--r-- | cmd/srv9p/gnet.c | 10 |
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; |