diff --git a/include/wx/gsocket.h b/include/wx/gsocket.h index 9916b9771e..3b0faf040b 100644 --- a/include/wx/gsocket.h +++ b/include/wx/gsocket.h @@ -277,6 +277,7 @@ GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname, GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname, const void *optval, int optlen); +GSocketError GSocket_SetReuseAddr(GSocket *socket); void GSocket_Streamed(GSocket *socket); void GSocket_Unstreamed(GSocket *socket); diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index c4f9345519..5cb994b838 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -109,11 +109,11 @@ void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *guifunc) { gs_gui_functions = guifunc; } - + int GSocket_Init(void) { WSADATA wsaData; - + if (gs_gui_functions) { if ( !gs_gui_functions->GUI_Init() ) @@ -130,7 +130,7 @@ void GSocket_Cleanup(void) { gs_gui_functions->GUI_Cleanup(); } - + /* Cleanup WinSocket */ WSACleanup(); } @@ -389,11 +389,6 @@ 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. @@ -777,7 +772,7 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) fd_set readfds; fd_set writefds; fd_set exceptfds; - + assert(socket != NULL); FD_ZERO(&readfds); @@ -829,7 +824,7 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) { socket->m_detected = GSOCK_LOST_FLAG; socket->m_establishing = FALSE; - + /* LOST event: Abort any further processing */ return (GSOCK_LOST_FLAG & flags); } @@ -1000,16 +995,25 @@ GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname, return GSOCK_OPTERR; } -GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname, +GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname, const void *optval, int optlen) { if (setsockopt(socket->m_fd, level, optname, optval, optlen) == 0) { - return GSOCK_NOERROR; + return GSOCK_NOERROR; } return GSOCK_OPTERR; } +GSocketError GSocket_SetReuseAddr(GSocket *socket) +{ + /* allow a socket to re-bind if the socket is in the TIME_WAIT + state after being previously closed. + */ + u_long arg = 1; + setsockopt(socket->m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); +} + void GSocket_Streamed(GSocket *socket) { socket->m_stream = TRUE; diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index bc68887a40..28b5f54307 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -483,11 +483,6 @@ 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. @@ -1149,6 +1144,15 @@ GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname, return GSOCK_OPTERR; } +GSocketError GSocket_SetReuseAddr(GSocket *socket) +{ + /* allow a socket to re-bind if the socket is in the TIME_WAIT + state after being previously closed. + */ + u_long arg = 1; + setsockopt(socket->m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); +} + void GSocket_Streamed(GSocket *socket) { socket->m_stream = TRUE;