diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index b4156f5afe..9eb8d69513 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -376,6 +376,11 @@ GSocketError GSocket_SetServer(GSocket *sck) ioctlsocket(sck->m_fd, FIONBIO, (u_long FAR *) &arg); _GSocket_Enable_Events(sck); + /* allow a socket to re-bind if the socket is in the TIME_WAIT + state after being previously closed. + */ + setsockopt(sck->m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); + /* Bind to the local address, * retrieve the actual address bound, * and listen up to 5 connections. diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index c7b0d7cf49..396a93641d 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -488,6 +488,11 @@ GSocketError GSocket_SetServer(GSocket *sck) #endif _GSocket_Enable_Events(sck); + /* allow a socket to re-bind if the socket is in the TIME_WAIT + state after being previously closed. + */ + setsockopt(sck->m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); + /* Bind to the local address, * retrieve the actual address bound, * and listen up to 5 connections.