summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/TcpTransceiver.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2007-02-01 17:09:49 +0000
committerBernard Normier <bernard@zeroc.com>2007-02-01 17:09:49 +0000
commitabada90e3f84dc703b8ddc9efcbed8a946fadead (patch)
tree2c6f9dccd510ea97cb927a7bd635422efaae547a /cpp/src/Ice/TcpTransceiver.cpp
parentremoving trace message (diff)
downloadice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.bz2
ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.xz
ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.zip
Expanded tabs into spaces
Diffstat (limited to 'cpp/src/Ice/TcpTransceiver.cpp')
-rw-r--r--cpp/src/Ice/TcpTransceiver.cpp452
1 files changed, 226 insertions, 226 deletions
diff --git a/cpp/src/Ice/TcpTransceiver.cpp b/cpp/src/Ice/TcpTransceiver.cpp
index 4eb5f54fa02..541843223b7 100644
--- a/cpp/src/Ice/TcpTransceiver.cpp
+++ b/cpp/src/Ice/TcpTransceiver.cpp
@@ -32,20 +32,20 @@ IceInternal::TcpTransceiver::close()
{
if(_traceLevels->network >= 1)
{
- Trace out(_logger, _traceLevels->networkCat);
- out << "closing tcp connection\n" << toString();
+ Trace out(_logger, _traceLevels->networkCat);
+ out << "closing tcp connection\n" << toString();
}
assert(_fd != INVALID_SOCKET);
try
{
- closeSocket(_fd);
- _fd = INVALID_SOCKET;
+ closeSocket(_fd);
+ _fd = INVALID_SOCKET;
}
catch(const SocketException&)
{
- _fd = INVALID_SOCKET;
- throw;
+ _fd = INVALID_SOCKET;
+ throw;
}
}
@@ -54,8 +54,8 @@ IceInternal::TcpTransceiver::shutdownWrite()
{
if(_traceLevels->network >= 2)
{
- Trace out(_logger, _traceLevels->networkCat);
- out << "shutting down tcp connection for writing\n" << toString();
+ Trace out(_logger, _traceLevels->networkCat);
+ out << "shutting down tcp connection for writing\n" << toString();
}
assert(_fd != INVALID_SOCKET);
@@ -67,8 +67,8 @@ IceInternal::TcpTransceiver::shutdownReadWrite()
{
if(_traceLevels->network >= 2)
{
- Trace out(_logger, _traceLevels->networkCat);
- out << "shutting down tcp connection for reading and writing\n" << toString();
+ Trace out(_logger, _traceLevels->networkCat);
+ out << "shutting down tcp connection for reading and writing\n" << toString();
}
assert(_fd != INVALID_SOCKET);
@@ -87,112 +87,112 @@ IceInternal::TcpTransceiver::write(Buffer& buf, int timeout)
//
if(_isPeerLocal && packetSize > 64 * 1024)
{
- packetSize = 64 * 1024;
+ packetSize = 64 * 1024;
}
#endif
while(buf.i != buf.b.end())
{
- assert(_fd != INVALID_SOCKET);
- ssize_t ret = ::send(_fd, reinterpret_cast<const char*>(&*buf.i), packetSize, 0);
-
- if(ret == 0)
- {
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
- }
-
- if(ret == SOCKET_ERROR)
- {
- if(interrupted())
- {
- continue;
- }
-
- if(noBuffers() && packetSize > 1024)
- {
- packetSize /= 2;
- continue;
- }
-
- if(wouldBlock())
- {
- repeatSelect:
-
- int rs;
- assert(_fd != INVALID_SOCKET);
+ assert(_fd != INVALID_SOCKET);
+ ssize_t ret = ::send(_fd, reinterpret_cast<const char*>(&*buf.i), packetSize, 0);
+
+ if(ret == 0)
+ {
+ ConnectionLostException ex(__FILE__, __LINE__);
+ ex.error = 0;
+ throw ex;
+ }
+
+ if(ret == SOCKET_ERROR)
+ {
+ if(interrupted())
+ {
+ continue;
+ }
+
+ if(noBuffers() && packetSize > 1024)
+ {
+ packetSize /= 2;
+ continue;
+ }
+
+ if(wouldBlock())
+ {
+ repeatSelect:
+
+ int rs;
+ assert(_fd != INVALID_SOCKET);
#ifdef _WIN32
- FD_SET(_fd, &_wFdSet);
-
- if(timeout >= 0)
- {
- struct timeval tv;
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
- rs = ::select(static_cast<int>(_fd + 1), 0, &_wFdSet, 0, &tv);
- }
- else
- {
- rs = ::select(static_cast<int>(_fd + 1), 0, &_wFdSet, 0, 0);
- }
+ FD_SET(_fd, &_wFdSet);
+
+ if(timeout >= 0)
+ {
+ struct timeval tv;
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
+ rs = ::select(static_cast<int>(_fd + 1), 0, &_wFdSet, 0, &tv);
+ }
+ else
+ {
+ rs = ::select(static_cast<int>(_fd + 1), 0, &_wFdSet, 0, 0);
+ }
#else
- struct pollfd pollFd[1];
- pollFd[0].fd = _fd;
- pollFd[0].events = POLLOUT;
- rs = ::poll(pollFd, 1, timeout);
-#endif
- if(rs == SOCKET_ERROR)
- {
- if(interrupted())
- {
- goto repeatSelect;
- }
-
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
- }
-
- if(rs == 0)
- {
- throw TimeoutException(__FILE__, __LINE__);
- }
-
- continue;
- }
-
- if(connectionLost())
- {
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
- }
- else
- {
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
- }
- }
-
- if(_traceLevels->network >= 3)
- {
- Trace out(_logger, _traceLevels->networkCat);
- out << "sent " << ret << " of " << packetSize << " bytes via tcp\n" << toString();
- }
-
- if(_stats)
- {
- _stats->bytesSent(type(), static_cast<Int>(ret));
- }
-
- buf.i += ret;
-
- if(packetSize > buf.b.end() - buf.i)
- {
- packetSize = static_cast<int>(buf.b.end() - buf.i);
- }
+ struct pollfd pollFd[1];
+ pollFd[0].fd = _fd;
+ pollFd[0].events = POLLOUT;
+ rs = ::poll(pollFd, 1, timeout);
+#endif
+ if(rs == SOCKET_ERROR)
+ {
+ if(interrupted())
+ {
+ goto repeatSelect;
+ }
+
+ SocketException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+
+ if(rs == 0)
+ {
+ throw TimeoutException(__FILE__, __LINE__);
+ }
+
+ continue;
+ }
+
+ if(connectionLost())
+ {
+ ConnectionLostException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+ else
+ {
+ SocketException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+ }
+
+ if(_traceLevels->network >= 3)
+ {
+ Trace out(_logger, _traceLevels->networkCat);
+ out << "sent " << ret << " of " << packetSize << " bytes via tcp\n" << toString();
+ }
+
+ if(_stats)
+ {
+ _stats->bytesSent(type(), static_cast<Int>(ret));
+ }
+
+ buf.i += ret;
+
+ if(packetSize > buf.b.end() - buf.i)
+ {
+ packetSize = static_cast<int>(buf.b.end() - buf.i);
+ }
}
}
@@ -204,125 +204,125 @@ IceInternal::TcpTransceiver::read(Buffer& buf, int timeout)
while(buf.i != buf.b.end())
{
- assert(_fd != INVALID_SOCKET);
- ssize_t ret = ::recv(_fd, reinterpret_cast<char*>(&*buf.i), packetSize, 0);
-
- 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);
- //shutdownSocketReadWrite(_fd);
-
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = 0;
- throw ex;
- }
-
- if(ret == SOCKET_ERROR)
- {
- if(interrupted())
- {
- continue;
- }
-
- if(noBuffers() && packetSize > 1024)
- {
- packetSize /= 2;
- continue;
- }
-
- if(wouldBlock())
- {
- repeatSelect:
-
- int rs;
- assert(_fd != INVALID_SOCKET);
+ assert(_fd != INVALID_SOCKET);
+ ssize_t ret = ::recv(_fd, reinterpret_cast<char*>(&*buf.i), packetSize, 0);
+
+ 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);
+ //shutdownSocketReadWrite(_fd);
+
+ ConnectionLostException ex(__FILE__, __LINE__);
+ ex.error = 0;
+ throw ex;
+ }
+
+ if(ret == SOCKET_ERROR)
+ {
+ if(interrupted())
+ {
+ continue;
+ }
+
+ if(noBuffers() && packetSize > 1024)
+ {
+ packetSize /= 2;
+ continue;
+ }
+
+ if(wouldBlock())
+ {
+ repeatSelect:
+
+ int rs;
+ assert(_fd != INVALID_SOCKET);
#ifdef _WIN32
- FD_SET(_fd, &_rFdSet);
-
- if(timeout >= 0)
- {
- struct timeval tv;
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
- rs = ::select(static_cast<int>(_fd + 1), &_rFdSet, 0, 0, &tv);
- }
- else
- {
- rs = ::select(static_cast<int>(_fd + 1), &_rFdSet, 0, 0, 0);
- }
+ FD_SET(_fd, &_rFdSet);
+
+ if(timeout >= 0)
+ {
+ struct timeval tv;
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
+ rs = ::select(static_cast<int>(_fd + 1), &_rFdSet, 0, 0, &tv);
+ }
+ else
+ {
+ rs = ::select(static_cast<int>(_fd + 1), &_rFdSet, 0, 0, 0);
+ }
#else
- struct pollfd pollFd[1];
- pollFd[0].fd = _fd;
- pollFd[0].events = POLLIN;
- rs = ::poll(pollFd, 1, timeout);
+ struct pollfd pollFd[1];
+ pollFd[0].fd = _fd;
+ pollFd[0].events = POLLIN;
+ rs = ::poll(pollFd, 1, timeout);
#endif
- if(rs == SOCKET_ERROR)
- {
- if(interrupted())
- {
- goto repeatSelect;
- }
-
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
- }
-
- if(rs == 0)
- {
- throw TimeoutException(__FILE__, __LINE__);
- }
-
- continue;
- }
-
- if(connectionLost())
- {
- //
- // See the commment above about shutting down the
- // socket if the connection is lost while reading
- // data.
- //
- //assert(_fd != INVALID_SOCKET);
- //shutdownSocketReadWrite(_fd);
-
- ConnectionLostException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
- }
- else
- {
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
- }
- }
-
- if(_traceLevels->network >= 3)
- {
- Trace out(_logger, _traceLevels->networkCat);
- out << "received " << ret << " of " << packetSize << " bytes via tcp\n" << toString();
- }
-
- if(_stats)
- {
- _stats->bytesReceived(type(), static_cast<Int>(ret));
- }
-
- buf.i += ret;
-
- if(packetSize > buf.b.end() - buf.i)
- {
- packetSize = static_cast<int>(buf.b.end() - buf.i);
- }
+ if(rs == SOCKET_ERROR)
+ {
+ if(interrupted())
+ {
+ goto repeatSelect;
+ }
+
+ SocketException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+
+ if(rs == 0)
+ {
+ throw TimeoutException(__FILE__, __LINE__);
+ }
+
+ continue;
+ }
+
+ if(connectionLost())
+ {
+ //
+ // See the commment above about shutting down the
+ // socket if the connection is lost while reading
+ // data.
+ //
+ //assert(_fd != INVALID_SOCKET);
+ //shutdownSocketReadWrite(_fd);
+
+ ConnectionLostException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+ else
+ {
+ SocketException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+ }
+
+ if(_traceLevels->network >= 3)
+ {
+ Trace out(_logger, _traceLevels->networkCat);
+ out << "received " << ret << " of " << packetSize << " bytes via tcp\n" << toString();
+ }
+
+ if(_stats)
+ {
+ _stats->bytesReceived(type(), static_cast<Int>(ret));
+ }
+
+ buf.i += ret;
+
+ if(packetSize > buf.b.end() - buf.i)
+ {
+ packetSize = static_cast<int>(buf.b.end() - buf.i);
+ }
}
}
@@ -348,7 +348,7 @@ IceInternal::TcpTransceiver::checkSendSize(const Buffer& buf, size_t messageSize
{
if(buf.b.size() > messageSizeMax)
{
- throw MemoryLimitException(__FILE__, __LINE__);
+ throw MemoryLimitException(__FILE__, __LINE__);
}
}