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 3b656cd..99895ad 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -440,11 +440,6 @@
}
#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 @@
}
#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;