Prevent TIME-WAIT connections from blocking listen address.

Of course Windows has to be retarded in its own special way and implement
SO_REUSEADDR with a completely different meaning.

http://www.andy-pearce.com/blog/posts/2013/Feb/so_reuseaddr-on-windows/
This commit is contained in:
Bartosz Taudul 2018-04-27 19:18:09 +02:00
parent 237aee30a8
commit eeeff40a70

View File

@ -228,6 +228,9 @@ bool ListenSocket::Listen( const char* port, int backlog )
#if defined _MSC_VER || defined __CYGWIN__
unsigned long val = 0;
setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) );
#else
int val = 1;
setsockopt( m_sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof( val ) );
#endif
if( bind( m_sock, res->ai_addr, res->ai_addrlen ) == -1 ) return false;
if( listen( m_sock, backlog ) == -1 ) return false;