summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-10-16 23:20:59 +0000
committerChris Wilson <chris+github@qwirx.com>2006-10-16 23:20:59 +0000
commit75da451418ba6092424f1f7e87f75da72e99a3f5 (patch)
treebadaa6138eb0568f9426ef0f3859a054dd87dc05 /lib
parent7d2a3c9eb51ac558c0dc70a2194f40935cc9b693 (diff)
Use more accurate sleeps in poll() to ensure that we don't end up busy
waiting for the last fraction of a second with repeated poll(..., 0). (refs #3)
Diffstat (limited to 'lib')
-rw-r--r--lib/server/SocketStreamTLS.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/server/SocketStreamTLS.cpp b/lib/server/SocketStreamTLS.cpp
index af4ad460..58dc5754 100644
--- a/lib/server/SocketStreamTLS.cpp
+++ b/lib/server/SocketStreamTLS.cpp
@@ -23,6 +23,7 @@
#include "SSLLib.h"
#include "ServerException.h"
#include "TLSContext.h"
+#include "BoxTime.h"
#include "MemLeakFindOn.h"
@@ -244,20 +245,30 @@ bool SocketStreamTLS::WaitWhenRetryRequired(int SSLErrorCode, int Timeout)
break;
}
p.revents = 0;
- switch(::poll(&p, 1, (Timeout == IOStream::TimeOutInfinite)?INFTIM:Timeout))
+
+ int64_t start, end;
+ start = BoxTimeToMilliSeconds(GetCurrentBoxTime());
+ end = start + Timeout;
+ int result;
+
+ do
{
- case -1:
- // error
- if(errno == EINTR)
- {
- // Signal. Do "time out"
- return false;
- }
- else
+ int64_t now = BoxTimeToMilliSeconds(GetCurrentBoxTime());
+ int poll_timeout = (int)(end - now);
+ if (poll_timeout < 0) poll_timeout = 0;
+ if (Timeout == IOStream::TimeOutInfinite)
{
- // Bad!
- THROW_EXCEPTION(ServerException, SocketPollError)
+ poll_timeout = INFTIM;
}
+ result = ::poll(&p, 1, poll_timeout);
+ }
+ while(result == -1 && errno == EINTR);
+
+ switch(result)
+ {
+ case -1:
+ // error - Bad!
+ THROW_EXCEPTION(ServerException, SocketPollError)
break;
case 0: