aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-12-17 21:38:45 +0000
committerVincent Richard <[email protected]>2013-12-17 21:38:45 +0000
commit645c572ab5b510967a5475743bed45c9e54439eb (patch)
treed0ca6b48eb826c65c8ea4eff4a29fb078702cc8f
parentLoop on recv and send operations for non-blocking sockets with OpenSSL. (diff)
downloadvmime-645c572ab5b510967a5475743bed45c9e54439eb.tar.gz
vmime-645c572ab5b510967a5475743bed45c9e54439eb.zip
Handle timeout in non-blocking send.
-rw-r--r--src/platforms/posix/posixSocket.cpp20
-rw-r--r--src/platforms/windows/windowsSocket.cpp20
2 files changed, 40 insertions, 0 deletions
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;
}