summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Network.cpp4
-rw-r--r--cpp/src/Ice/TcpAcceptor.cpp15
-rw-r--r--cpp/src/Ice/UdpTransceiver.cpp15
-rw-r--r--cpp/src/IceSSL/AcceptorI.cpp15
4 files changed, 45 insertions, 4 deletions
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index a1710cd34ae..0bc6ff1f114 100644
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -536,10 +536,6 @@ IceInternal::setReuseAddress(SOCKET fd, bool reuse)
void
IceInternal::doBind(SOCKET fd, struct sockaddr_in& addr)
{
-#ifndef _WIN32
- setReuseAddress(fd, true);
-#endif
-
if(bind(fd, reinterpret_cast<struct sockaddr*>(&addr), int(sizeof(addr))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
diff --git a/cpp/src/Ice/TcpAcceptor.cpp b/cpp/src/Ice/TcpAcceptor.cpp
index 2ffb6fd5a0d..3d3c28b787d 100644
--- a/cpp/src/Ice/TcpAcceptor.cpp
+++ b/cpp/src/Ice/TcpAcceptor.cpp
@@ -121,6 +121,21 @@ IceInternal::TcpAcceptor::TcpAcceptor(const InstancePtr& instance, const string&
setBlock(_fd, false);
getAddress(host, port, _addr);
setTcpBufSize(_fd, _instance->initializationData().properties, _logger);
+#ifndef _WIN32
+ //
+ // Enable SO_REUSEADDR on Unix platforms to allow re-using the
+ // socket even if it's in the TIME_WAIT state. On Windows,
+ // this doesn't appear to be necessary and enabling
+ // SO_REUSEADDR would actually not be a good thing since it
+ // allows a second process to bind to an address even it's
+ // already bound by another process.
+ //
+ // TODO: using SO_EXCLUSIVEADDRUSE on Windows would probably
+ // be better but it's only supported by recent Windows
+ // versions (XP SP2, Windows Server 2003).
+ //
+ setReuseAddress(_fd, true);
+#endif
if(_traceLevels->network >= 2)
{
Trace out(_logger, _traceLevels->networkCat);
diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp
index 67e2b33bc78..1fa3fb8e5eb 100644
--- a/cpp/src/Ice/UdpTransceiver.cpp
+++ b/cpp/src/Ice/UdpTransceiver.cpp
@@ -474,6 +474,21 @@ IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const s
}
else
{
+#ifndef _WIN32
+ //
+ // Enable SO_REUSEADDR on Unix platforms to allow re-using
+ // the socket even if it's in the TIME_WAIT state. On
+ // Windows, this doesn't appear to be necessary and
+ // enabling SO_REUSEADDR would actually not be a good
+ // thing since it allows a second process to bind to an
+ // address even it's already bound by another process.
+ //
+ // TODO: using SO_EXCLUSIVEADDRUSE on Windows would
+ // probably be better but it's only supported by recent
+ // Windows versions (XP SP2, Windows Server 2003).
+ //
+ setReuseAddress(_fd, true);
+#endif
doBind(_fd, _addr);
}
diff --git a/cpp/src/IceSSL/AcceptorI.cpp b/cpp/src/IceSSL/AcceptorI.cpp
index b2fec924caa..b5c59c183c2 100644
--- a/cpp/src/IceSSL/AcceptorI.cpp
+++ b/cpp/src/IceSSL/AcceptorI.cpp
@@ -157,6 +157,21 @@ IceSSL::AcceptorI::AcceptorI(const InstancePtr& instance, const string& adapterN
IceInternal::setBlock(_fd, false);
IceInternal::getAddress(host, port, _addr);
IceInternal::setTcpBufSize(_fd, _instance->communicator()->getProperties(), _logger);
+#ifndef _WIN32
+ //
+ // Enable SO_REUSEADDR on Unix platforms to allow re-using the
+ // socket even if it's in the TIME_WAIT state. On Windows,
+ // this doesn't appear to be necessary and enabling
+ // SO_REUSEADDR would actually not be a good thing since it
+ // allows a second process to bind to an address even it's
+ // already bound by another process.
+ //
+ // TODO: using SO_EXCLUSIVEADDRUSE on Windows would probably
+ // be better but it's only supported by recent Windows
+ // versions (XP SP2, Windows Server 2003).
+ //
+ IceInternal::setReuseAddress(_fd, true);
+#endif
if(_instance->networkTraceLevel() >= 2)
{
Trace out(_logger, _instance->networkTraceCategory());