set SO_REUSEADDR before binding for UDP sockets too (2nd part of patch 1667145)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44720 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-03-10 16:17:44 +00:00
parent deda45e8c2
commit 01ba4b6713

View File

@@ -762,7 +762,7 @@ GSocketError GSocket::SetServer()
/* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */ /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
#ifdef SO_NOSIGPIPE #ifdef SO_NOSIGPIPE
setsockopt(m_fd, SOL_SOCKET, SO_NOSIGPIPE, (const char*)&arg, sizeof(u_long)); setsockopt(m_fd, SOL_SOCKET, SO_NOSIGPIPE, (const char*)&arg, sizeof(arg));
#endif #endif
ioctl(m_fd, FIONBIO, &arg); ioctl(m_fd, FIONBIO, &arg);
@@ -773,9 +773,9 @@ GSocketError GSocket::SetServer()
*/ */
if (m_reusable) 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(arg));
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(u_long)); setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(arg));
#endif #endif
} }
@@ -967,7 +967,7 @@ GSocketError GSocket::Connect(GSocketStream stream)
/* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */ /* FreeBSD variants can't use MSG_NOSIGNAL, and instead use a socket option */
#ifdef SO_NOSIGPIPE #ifdef SO_NOSIGPIPE
setsockopt(m_fd, SOL_SOCKET, SO_NOSIGPIPE, (const char*)&arg, sizeof(u_long)); setsockopt(m_fd, SOL_SOCKET, SO_NOSIGPIPE, (const char*)&arg, sizeof(arg));
#endif #endif
#if defined(__EMX__) || defined(__VISAGECPP__) #if defined(__EMX__) || defined(__VISAGECPP__)
@@ -979,9 +979,9 @@ GSocketError GSocket::Connect(GSocketStream stream)
// If the reuse flag is set, use the applicable socket reuse flags(s) // If the reuse flag is set, use the applicable socket reuse flags(s)
if (m_reusable) 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(arg));
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(u_long)); setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(arg));
#endif #endif
} }
@@ -1111,6 +1111,14 @@ GSocketError GSocket::SetNonOriented()
#endif #endif
gs_gui_functions->Enable_Events(this); gs_gui_functions->Enable_Events(this);
if (m_reusable)
{
setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(arg));
#ifdef SO_REUSEPORT
setsockopt(m_fd, SOL_SOCKET, SO_REUSEPORT, (const char*)&arg, sizeof(arg));
#endif
}
/* Bind to the local address, /* Bind to the local address,
* and retrieve the actual address bound. * and retrieve the actual address bound.
*/ */