Incorporated src/unix/gsocket.c 1.86 to 1.92 changes (except 1.90 to 1.91

which was applied by Vadim as 1.9 to 1.10 of src/unix/gsocket.cpp)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28515 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2004-07-27 02:15:32 +00:00
parent 2d080a4963
commit b082b52407
2 changed files with 67 additions and 24 deletions

View File

@@ -44,6 +44,7 @@ public:
GAddress *GetPeer(); GAddress *GetPeer();
GSocketError SetServer(); GSocketError SetServer();
GSocket *WaitConnection(); GSocket *WaitConnection();
int SetReusable();
GSocketError Connect(GSocketStream stream); GSocketError Connect(GSocketStream stream);
GSocketError SetNonOriented(); GSocketError SetNonOriented();
int Read(char *buffer, int size); int Read(char *buffer, int size);
@@ -55,6 +56,9 @@ public:
void SetCallback(GSocketEventFlags flags, void SetCallback(GSocketEventFlags flags,
GSocketCallback callback, char *cdata); GSocketCallback callback, char *cdata);
void UnsetCallback(GSocketEventFlags flags); void UnsetCallback(GSocketEventFlags flags);
GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen);
GSocketError SetSockOpt(int level, int optname,
const void *optval, int optlen);
/* API compatibility functions */ /* API compatibility functions */
static void _GSocket_Detected_Read(GSocket *socket); static void _GSocket_Detected_Read(GSocket *socket);
static void _GSocket_Detected_Write(GSocket *socket); static void _GSocket_Detected_Write(GSocket *socket);
@@ -172,6 +176,8 @@ inline GSocketError GSocket_SetServer(GSocket *socket)
{ return socket->SetServer(); } { return socket->SetServer(); }
inline GSocket *GSocket_WaitConnection(GSocket *socket) inline GSocket *GSocket_WaitConnection(GSocket *socket)
{ return socket->WaitConnection(); } { return socket->WaitConnection(); }
inline int GSocket_SetReusable(GSocket *socket)
{ return socket->SetReusable(); }
inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream) inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
{ return socket->Connect(stream); } { return socket->Connect(stream); }
inline GSocketError GSocket_SetNonOriented(GSocket *socket) inline GSocketError GSocket_SetNonOriented(GSocket *socket)
@@ -191,6 +197,12 @@ inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
{ socket->SetCallback(flags,fallback,cdata); } { socket->SetCallback(flags,fallback,cdata); }
inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags) inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
{ socket->UnsetCallback(flags); } { socket->UnsetCallback(flags); }
inline GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname,
void *optval, int *optlen)
{ return socket->GetSockOpt(level,optname,optval,optlen); }
inline GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname,
const void *optval, int optlen)
{ return socket->SetSockOpt(level,optname,optval,optlen); }
#endif /* def wxUSE_GSOCKET_CPLUSPLUS */ #endif /* def wxUSE_GSOCKET_CPLUSPLUS */

View File

@@ -475,6 +475,7 @@ GSocketError GSocketBSD::SetServer()
/* allow a socket to re-bind if the socket is in the TIME_WAIT /* allow a socket to re-bind if the socket is in the TIME_WAIT
state after being previously closed. state after being previously closed.
*/ */
if(m_reusable)
setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long));
/* Bind to the local address, /* Bind to the local address,
@@ -588,6 +589,16 @@ GSocket *GSocketBSD::WaitConnection()
return connection; return connection;
} }
int GSocketBSD::SetReusable()
{
/* socket must not be null, and must not be in use/already bound */
if (NULL != this && m_fd == INVALID_SOCKET) {
m_reusable = TRUE;
return TRUE;
}
return FALSE;
}
/* Client specific parts */ /* Client specific parts */
/* GSocket_Connect: /* GSocket_Connect:
@@ -1117,6 +1128,26 @@ void GSocketBSD::UnsetCallback(GSocketEventFlags flags)
} }
GSocketError GSocketBSD::GetSockOpt(int level, int optname,
void *optval, int *optlen)
{
if (getsockopt(m_fd, level, optname, optval, optlen) == 0)
{
return GSOCK_NOERROR;
}
return GSOCK_OPTERR;
}
GSocketError GSocketBSD::SetSockOpt(int level, int optname,
const void *optval, int optlen)
{
if (setsockopt(m_fd, level, optname, optval, optlen) == 0)
{
return GSOCK_NOERROR;
}
return GSOCK_OPTERR;
}
#define CALL_CALLBACK(event) { \ #define CALL_CALLBACK(event) { \
Disable(event); \ Disable(event); \
if (m_cbacks[event]) \ if (m_cbacks[event]) \