1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Tweaked the re-use flags for DatagramSocket

This commit is contained in:
jules 2014-10-16 17:25:12 +01:00
parent 30e66ba5d8
commit 205498900a

View file

@ -263,6 +263,12 @@ namespace SocketHelpers
return true;
}
static void makeReusable (int handle) noexcept
{
const int reuse = 1;
setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
}
}
//==============================================================================
@ -419,8 +425,7 @@ bool StreamingSocket::createListener (const int newPortNumber, const String& loc
return false;
#if ! JUCE_WINDOWS // on windows, adding this option produces behaviour different to posix
const int reuse = 1;
setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
SocketHelpers::makeReusable (handle);
#endif
if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
@ -472,6 +477,7 @@ DatagramSocket::DatagramSocket (const int localPortNumber, const bool canBroadca
SocketHelpers::initSockets();
handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
SocketHelpers::makeReusable (handle);
bindToPort (localPortNumber);
}