11//
22// SocketImpl.cpp
33//
4- // $Id: //poco/Main/Net/src/SocketImpl.cpp#22 $
4+ // $Id: //poco/Main/Net/src/SocketImpl.cpp#23 $
55//
66// Library: Net
77// Package: Sockets
@@ -220,6 +220,14 @@ int SocketImpl::sendBytes(const void* buffer, int length, int flags)
220220{
221221 poco_assert (_sockfd != POCO_INVALID_SOCKET);
222222
223+ #if defined(POCO_BROKEN_TIMEOUTS)
224+ if (_sndTimeout.totalMicroseconds () != 0 )
225+ {
226+ if (!poll (_sndTimeout, SELECT_WRITE))
227+ throw TimeoutException ();
228+ }
229+ #endif
230+
223231 int rc;
224232 do
225233 {
@@ -359,7 +367,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
359367 {
360368 Poco::Timestamp end;
361369 Poco::Timespan waited = end - start;
362- if (waited > remainingTime)
370+ if (waited < remainingTime)
363371 remainingTime -= waited;
364372 else
365373 remainingTime = 0 ;
@@ -404,6 +412,8 @@ void SocketImpl::setSendTimeout(const Poco::Timespan& timeout)
404412#if defined(_WIN32)
405413 int value = (int ) timeout.totalMilliseconds ();
406414 setOption (SOL_SOCKET, SO_SNDTIMEO, value);
415+ #elif defined(POCO_BROKEN_TIMEOUTS)
416+ _sndTimeout = timeout;
407417#else
408418 setOption (SOL_SOCKET, SO_SNDTIMEO, timeout);
409419#endif
@@ -417,6 +427,8 @@ Poco::Timespan SocketImpl::getSendTimeout()
417427 int value;
418428 getOption (SOL_SOCKET, SO_SNDTIMEO, value);
419429 result = Timespan::TimeDiff (value)*1000 ;
430+ #elif defined(POCO_BROKEN_TIMEOUTS)
431+ result = _sndTimeout;
420432#else
421433 getOption (SOL_SOCKET, SO_SNDTIMEO, result);
422434#endif
@@ -426,13 +438,14 @@ Poco::Timespan SocketImpl::getSendTimeout()
426438
427439void SocketImpl::setReceiveTimeout (const Poco::Timespan& timeout)
428440{
441+ #ifndef POCO_BROKEN_TIMEOUTS
429442#if defined(_WIN32)
430443 int value = (int ) timeout.totalMilliseconds ();
431444 setOption (SOL_SOCKET, SO_RCVTIMEO, value);
432445#else
433- setOption (SOL_SOCKET, SO_RCVTIMEO, timeout);
446+ setOption (SOL_SOCKET, SO_RCVTIMEO, timeout);
434447#endif
435- #if defined(POCO_BROKEN_TIMEOUTS)
448+ #else
436449 _recvTimeout = timeout;
437450#endif
438451}
0 commit comments