Handle timeout in non-blocking send.

This commit is contained in:
Vincent Richard 2013-12-17 22:38:45 +01:00
parent 2b62c675fa
commit 645c572ab5
2 changed files with 40 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}