From: Pierre Ossman Date: Thu, 23 Apr 2015 09:23:16 +0000 (+0200) Subject: Repair SO_REUSEADDR X-Git-Tag: v1.4.90~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b6536e250a7ce5cd3a4d7415f3dbc79e18b71e53;p=tigervnc.git Repair SO_REUSEADDR SO_REUSEADDR needs to be set before we call bind() for it to have any effect. It got shuffled around in e4d9726. --- diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 3b656cd7..99895ad8 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -440,11 +440,6 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, } #endif /* defined(IPV6_V6ONLY) */ - if (bind(sock, &sa.u.sa, listenaddrlen) == -1) { - closesocket(sock); - throw SocketException("failed to bind socket", errorNumber); - } - #ifndef WIN32 // - By default, close the socket on exec() fcntl(sock, F_SETFD, FD_CLOEXEC); @@ -457,6 +452,11 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, } #endif + if (bind(sock, &sa.u.sa, listenaddrlen) == -1) { + closesocket(sock); + throw SocketException("failed to bind socket", errorNumber); + } + // - Set it to be a listening socket if (listen(sock, 5) < 0) { int e = errorNumber;