summaryrefslogtreecommitdiff
path: root/cppe/src
diff options
context:
space:
mode:
Diffstat (limited to 'cppe/src')
-rw-r--r--cppe/src/IceE/Network.cpp22
-rw-r--r--cppe/src/IceE/Network.h1
-rw-r--r--cppe/src/TcpTransport/Acceptor.cpp15
3 files changed, 28 insertions, 10 deletions
diff --git a/cppe/src/IceE/Network.cpp b/cppe/src/IceE/Network.cpp
index 5338648cf1a..d1b9702333a 100644
--- a/cppe/src/IceE/Network.cpp
+++ b/cppe/src/IceE/Network.cpp
@@ -450,19 +450,21 @@ IceInternal::getRecvBufferSize(SOCKET fd)
}
void
-IceInternal::doBind(SOCKET fd, struct sockaddr_in& addr)
+IceInternal::setReuseAddress(SOCKET fd, bool reuse)
{
-#ifndef _WIN32
- int flag = 1;
+ int flag = reuse ? 1 : 0;
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&flag, int(sizeof(int))) == SOCKET_ERROR)
{
- closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ closeSocketNoThrow(fd);
+ SocketException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
}
-#endif
+}
+void
+IceInternal::doBind(SOCKET fd, struct sockaddr_in& addr)
+{
if(bind(fd, reinterpret_cast<struct sockaddr*>(&addr), int(sizeof(addr))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
@@ -1109,11 +1111,11 @@ IceInternal::setTcpBufSize(SOCKET fd, const Ice::PropertiesPtr& properties, cons
assert(fd != INVALID_SOCKET);
//
- // By default, on Windows we use a 128KB buffer size. On Unix
+ // By default, on Windows we use a 64KB buffer size. On Unix
// platforms, we use the system defaults.
//
#ifdef _WIN32
- const int dfltBufSize = 128 * 1024;
+ const int dfltBufSize = 64 * 1024;
#else
const int dfltBufSize = 0;
#endif
diff --git a/cppe/src/IceE/Network.h b/cppe/src/IceE/Network.h
index d7f95cb634d..2274bee007c 100644
--- a/cppe/src/IceE/Network.h
+++ b/cppe/src/IceE/Network.h
@@ -97,6 +97,7 @@ void setSendBufferSize(SOCKET, int);
int getSendBufferSize(SOCKET);
void setRecvBufferSize(SOCKET, int);
int getRecvBufferSize(SOCKET);
+void setReuseAddress(SOCKET, bool);
void doBind(SOCKET, struct sockaddr_in&);
void doListen(SOCKET, int);
diff --git a/cppe/src/TcpTransport/Acceptor.cpp b/cppe/src/TcpTransport/Acceptor.cpp
index 72e53c7ace9..b32928219ec 100644
--- a/cppe/src/TcpTransport/Acceptor.cpp
+++ b/cppe/src/TcpTransport/Acceptor.cpp
@@ -116,6 +116,21 @@ IceInternal::Acceptor::Acceptor(const InstancePtr& instance, const string& host,
_fd = createSocket();
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);