diff options
Diffstat (limited to 'cppe/src')
-rw-r--r-- | cppe/src/TcpTransport/Acceptor.cpp | 7 | ||||
-rw-r--r-- | cppe/src/TcpTransport/Connector.cpp | 7 | ||||
-rw-r--r-- | cppe/src/TcpTransport/Transceiver.cpp | 36 |
3 files changed, 40 insertions, 10 deletions
diff --git a/cppe/src/TcpTransport/Acceptor.cpp b/cppe/src/TcpTransport/Acceptor.cpp index eae64c0a4aa..a2d0f4b365f 100644 --- a/cppe/src/TcpTransport/Acceptor.cpp +++ b/cppe/src/TcpTransport/Acceptor.cpp @@ -66,7 +66,14 @@ TransceiverPtr IceInternal::Acceptor::accept() { SOCKET fd = doAccept(_fd); +#if !defined(_WIN32) || defined(ICEE_USE_SOCKET_TIMEOUT) + // + // TODO: We can't use blocking sockets on Windows yet because + // the transceiver is using WSAEventSelect (which doesn't play + // well with blocking sockets). + // setBlock(fd, true); +#endif if(_traceLevels->network >= 1) { diff --git a/cppe/src/TcpTransport/Connector.cpp b/cppe/src/TcpTransport/Connector.cpp index 1825301e8fe..33f5876b34c 100644 --- a/cppe/src/TcpTransport/Connector.cpp +++ b/cppe/src/TcpTransport/Connector.cpp @@ -34,7 +34,14 @@ Connector::connect(int timeout) SOCKET fd = createSocket(); setBlock(fd, false); doConnect(fd, _addr, timeout); +#if !defined(_WIN32) || defined(ICEE_USE_SOCKET_TIMEOUT) + // + // TODO: We can't use blocking sockets on Windows yet because + // the transceiver is using WSAEventSelect (which doesn't play + // well with blocking sockets). + // setBlock(fd, true); +#endif if(_traceLevels->network >= 1) { diff --git a/cppe/src/TcpTransport/Transceiver.cpp b/cppe/src/TcpTransport/Transceiver.cpp index 5809ec869fc..612baa50873 100644 --- a/cppe/src/TcpTransport/Transceiver.cpp +++ b/cppe/src/TcpTransport/Transceiver.cpp @@ -39,6 +39,7 @@ IceInternal::Transceiver::close() out << "closing tcp connection\n" << toString(); } +#ifndef ICEE_USE_SOCKET_TIMEOUT #ifdef _WIN32 assert(_event != 0); WSACloseEvent(_event); @@ -48,6 +49,7 @@ IceInternal::Transceiver::close() _readEvent = 0; _writeEvent = 0; #endif +#endif assert(_fd != INVALID_SOCKET); try @@ -109,10 +111,7 @@ IceInternal::Transceiver::write(Buffer& buf, int timeout) while(buf.i != buf.b.end()) { #ifndef ICEE_USE_SOCKET_TIMEOUT - if(timeout > 0) - { - doSelect(false, timeout); - } +// doSelect(false, timeout); #else setTimeout(_fd, false, timeout); #endif @@ -148,6 +147,12 @@ IceInternal::Transceiver::write(Buffer& buf, int timeout) } #endif + if(wouldBlock()) + { + doSelect(false, timeout); + continue; + } + if(connectionLost()) { ConnectionLostException ex(__FILE__, __LINE__); @@ -187,13 +192,13 @@ IceInternal::Transceiver::read(Buffer& buf, int timeout) while(buf.i != buf.b.end()) { -#ifndef ICEE_USE_SOCKET_TIMEOUT +#if defined(ICEE_USE_SOCKET_TIMEOUT) + setTimeout(_fd, true, timeout); +#elif !defined(_WIN32) if(timeout > 0) { doSelect(true, timeout); } -#else - setTimeout(_fd, true, timeout); #endif repeatRead: @@ -231,12 +236,19 @@ IceInternal::Transceiver::read(Buffer& buf, int timeout) goto repeatRead; } -#ifdef ICEE_USE_SOCKET_TIMEOUT +#if defined(ICEE_USE_SOCKET_TIMEOUT) if(wouldBlock()) { throw TimeoutException(__FILE__, __LINE__); } +#elif defined(_WIN32) + if(wouldBlock()) + { + doSelect(true, timeout); + continue; + } #endif + if(connectionLost()) { // @@ -295,6 +307,7 @@ IceInternal::Transceiver::Transceiver(const InstancePtr& instance, SOCKET fd) : , _isPeerLocal(isPeerLocal(fd)) #endif { +#ifndef ICEE_USE_SOCKET_TIMEOUT #ifdef _WIN32 _event = WSACreateEvent(); _readEvent = WSACreateEvent(); @@ -341,22 +354,24 @@ IceInternal::Transceiver::Transceiver(const InstancePtr& instance, SOCKET fd) : FD_ZERO(&_wFdSet); FD_ZERO(&_rFdSet); #endif +#endif } IceInternal::Transceiver::~Transceiver() { assert(_fd == INVALID_SOCKET); +#ifndef ICEE_USE_SOCKET_TIMEOUT #ifdef _WIN32 assert(_event == 0); assert(_readEvent == 0); assert(_writeEvent == 0); #endif +#endif } void IceInternal::Transceiver::doSelect(bool read, int timeout) { - assert(timeout >= 0); while(true) { #ifdef _WIN32 @@ -367,7 +382,8 @@ IceInternal::Transceiver::doSelect(bool read, int timeout) WSAEVENT events[2]; events[0] = _event; events[1] = read ? _readEvent : _writeEvent; - DWORD rc = WSAWaitForMultipleEvents(2, events, FALSE, timeout, FALSE); + long tout = (timeout >= 0) ? timeout : WSA_INFINITE; + DWORD rc = WSAWaitForMultipleEvents(2, events, FALSE, tout, FALSE); if(rc == WSA_WAIT_FAILED) { SocketException ex(__FILE__, __LINE__); |