From d522221668e4ab7bb925b01c276ac462c899bcbf Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 8 Dec 2009 01:21:35 +0100 Subject: Fix restarting of tinyproxy: call setsockopt with REUSEADDR _before_ calling bind Somehow this got moved too far down in the ipv6 changes. Thanks to Mathew Mrosko for helping me debugging this. Michael --- src/sock.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/sock.c') diff --git a/src/sock.c b/src/sock.c index be50376..bf32c78 100644 --- a/src/sock.c +++ b/src/sock.c @@ -163,7 +163,7 @@ int socket_blocking (int sock) * Start listening to a socket. Create a socket with the selected port. * The size of the socket address will be returned to the caller through * the pointer, while the socket is returned as a default return. - * - rjkaes + * - rjkaes */ int listen_sock (uint16_t port, socklen_t * addrlen) { @@ -194,6 +194,9 @@ int listen_sock (uint16_t port, socklen_t * addrlen) if (listenfd == -1) continue; + setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on, + sizeof (on)); + if (bind (listenfd, rp->ai_addr, rp->ai_addrlen) == 0) break; /* success */ @@ -210,8 +213,6 @@ int listen_sock (uint16_t port, socklen_t * addrlen) return -1; } - setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)); - if (listen (listenfd, MAXLISTEN) < 0) { log_message (LOG_ERR, "Unable to start listening socket because of %s", -- cgit v1.2.3