diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp index e245bd95..ab434116 100644 --- a/src/platforms/posix/posixSocket.cpp +++ b/src/platforms/posix/posixSocket.cpp @@ -582,12 +582,32 @@ size_t posixSocket::sendRawNonBlocking(const byte_t* buffer, const size_t count) if (ret < 0 && !IS_EAGAIN(errno)) throwSocketError(errno); + // Check if we are timed out + if (m_timeoutHandler && + m_timeoutHandler->isTimeOut()) + { + if (!m_timeoutHandler->handleTimeOut()) + { + // Could not send data within timeout delay + throwSocketError(errno); + } + else + { + // Reset timeout + m_timeoutHandler->resetTimeOut(); + } + } + m_status |= STATUS_WOULDBLOCK; // No data can be written at this time return 0; } + // Reset timeout + if (m_timeoutHandler) + m_timeoutHandler->resetTimeOut(); + return ret; } diff --git a/src/platforms/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp index 2cad21c0..40e69363 100644 --- a/src/platforms/windows/windowsSocket.cpp +++ b/src/platforms/windows/windowsSocket.cpp @@ -362,6 +362,22 @@ size_t windowsSocket::sendRawNonBlocking(const char* buffer, const size_t count) if (err == WSAEWOULDBLOCK) { + // Check if we are timed out + if (m_timeoutHandler && + m_timeoutHandler->isTimeOut()) + { + if (!m_timeoutHandler->handleTimeOut()) + { + // Could not send data within timeout delay + throwSocketError(err); + } + else + { + // Reset timeout + m_timeoutHandler->resetTimeOut(); + } + } + m_status |= STATUS_WOULDBLOCK; // No data can be written at this time @@ -373,6 +389,10 @@ size_t windowsSocket::sendRawNonBlocking(const char* buffer, const size_t count) } } + // Reset timeout + if (m_timeoutHandler) + m_timeoutHandler->resetTimeOut(); + return ret; }