don't set SO_REUSEADDR by default; added GSocket_SetReuseAddr()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28463 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2004-07-25 12:40:10 +00:00
parent 8158e0e169
commit 7df69621d9
3 changed files with 26 additions and 17 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;