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
master
Michael Adam 2009-12-08 01:21:35 +01:00
parent 5bba62bcde
commit d522221668
1 changed files with 4 additions and 3 deletions

View File

@ -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",