From e9ad621443cb84799297f85e735fec7c2be159cc Mon Sep 17 00:00:00 2001 From: David Hummel <6109326+hummeltech@users.noreply.github.com> Date: Sun, 24 Mar 2024 16:21:40 -0700 Subject: [PATCH] Enable SO_REUSE{ADDR,PORT} for TCP/IP server sockets --- src/renderd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/renderd.c b/src/renderd.c index 6a805359..8fa98f4b 100644 --- a/src/renderd.c +++ b/src/renderd.c @@ -494,6 +494,8 @@ int server_socket_init(renderd_config *sConfig) int fd; if (sConfig->ipport > 0) { + const int enable = 1; + g_logger(G_LOG_LEVEL_INFO, "Initialising TCP/IP server socket on %s:%i", sConfig->iphostname, sConfig->ipport); fd = socket(PF_INET6, SOCK_STREAM, 0); @@ -503,6 +505,18 @@ int server_socket_init(renderd_config *sConfig) exit(2); } + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) { + g_logger(G_LOG_LEVEL_CRITICAL, "setsockopt SO_REUSEADDR failed for: %s:%i", + sConfig->iphostname, sConfig->ipport); + exit(3); + } + + if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable)) < 0) { + g_logger(G_LOG_LEVEL_CRITICAL, "setsockopt SO_REUSEPORT failed for: %s:%i", + sConfig->iphostname, sConfig->ipport); + exit(3); + } + bzero(&addrI, sizeof(addrI)); addrI.sin6_family = AF_INET6; addrI.sin6_addr = in6addr_any;