summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/TcpTransceiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/TcpTransceiver.cpp')
-rw-r--r--cpp/src/Ice/TcpTransceiver.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/cpp/src/Ice/TcpTransceiver.cpp b/cpp/src/Ice/TcpTransceiver.cpp
index b0196073949..6b57e537bff 100644
--- a/cpp/src/Ice/TcpTransceiver.cpp
+++ b/cpp/src/Ice/TcpTransceiver.cpp
@@ -193,6 +193,17 @@ IceInternal::TcpTransceiver::read(Buffer& buf, int timeout)
if(ret == 0)
{
+ //
+ // If the connection is lost when reading data, we shut
+ // down the write end of the socket. This helps to unblock
+ // threads that are stuck in send() or select() while
+ // sending data. Note: I don't really understand why
+ // send() or select() sometimes don't detect a connection
+ // loss. Therefore this helper to make them detect it.
+ //
+ assert(_fd != INVALID_SOCKET);
+ shutdownSocket(_fd);
+
ConnectionLostException ex(__FILE__, __LINE__);
ex.error = 0;
throw ex;
@@ -253,6 +264,14 @@ IceInternal::TcpTransceiver::read(Buffer& buf, int timeout)
if(connectionLost())
{
+ //
+ // See the commment above about shutting down the
+ // socket if the connection is lost while reading
+ // data.
+ //
+ assert(_fd != INVALID_SOCKET);
+ shutdownSocket(_fd);
+
ConnectionLostException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
throw ex;