Set SO_EXCLUSIVEADDRUSE for server sockets on Windows. (#44)

On Windows, the shutdown() call relies on exclusively owning the server
socket.
This commit is contained in:
Peter Johnson
2017-11-11 16:27:33 -08:00
committed by GitHub
parent 5a5e753921
commit f77fd1eca9

View File

@@ -99,8 +99,13 @@ int TCPAcceptor::start() {
}
address.sin_port = htons(m_port);
#ifdef _WIN32
int optval = 1;
setsockopt(m_lsd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char*)&optval, sizeof optval);
#else
int optval = 1;
setsockopt(m_lsd, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof optval);
#endif
int result = bind(m_lsd, (struct sockaddr*)&address, sizeof(address));
if (result != 0) {