diff options
Diffstat (limited to 'lib/server/SocketStream.h')
-rw-r--r-- | lib/server/SocketStream.h | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/server/SocketStream.h b/lib/server/SocketStream.h index 406d29e4..c3a67cb0 100644 --- a/lib/server/SocketStream.h +++ b/lib/server/SocketStream.h @@ -59,19 +59,33 @@ protected: void MarkAsWriteClosed() {mWriteClosed = true;} void CheckForMissingTimeout(int Timeout); - int PollTimeout(box_time_t Timeout) + int PollTimeout(int timeout, box_time_t start_time) { - if (Timeout < 0) + if (timeout == IOStream::TimeOutInfinite) { - return 0; + return INFTIM; } - else if (Timeout == IOStream::TimeOutInfinite || Timeout > INT_MAX) + + if (start_time == 0) { - return INFTIM; + return timeout; // no adjustment possible + } + + box_time_t end_time = start_time + MilliSecondsToBoxTime(timeout); + box_time_t now = GetCurrentBoxTime(); + box_time_t remaining = end_time - now; + + if (remaining < 0) + { + return 0; // no delay + } + else if (BoxTimeToMilliSeconds(remaining) > INT_MAX) + { + return INT_MAX; } else { - return (int) Timeout; + return (int) BoxTimeToMilliSeconds(remaining); } } bool Poll(short Events, int Timeout); |