[Box Backup-commit] COMMIT r3371 - box/trunk/lib/server
subversion at boxbackup.org
subversion at boxbackup.org
Fri Aug 15 23:48:10 BST 2014
Author: chris
Date: 2014-08-15 23:48:10 +0100 (Fri, 15 Aug 2014)
New Revision: 3371
Modified:
box/trunk/lib/server/SocketStream.cpp
box/trunk/lib/server/SocketStream.h
Log:
Fix poll timeout calculation for infinite timeouts.
Modified: box/trunk/lib/server/SocketStream.cpp
===================================================================
--- box/trunk/lib/server/SocketStream.cpp 2014-08-15 22:48:07 UTC (rev 3370)
+++ box/trunk/lib/server/SocketStream.cpp 2014-08-15 22:48:10 UTC (rev 3371)
@@ -218,7 +218,7 @@
p.fd = mSocketHandle;
p.events = POLLIN;
p.revents = 0;
- switch(::poll(&p, 1, PollTimeout(Timeout)))
+ switch(::poll(&p, 1, PollTimeout(Timeout, 0)))
{
case -1:
// error
@@ -287,13 +287,11 @@
p.revents = 0;
box_time_t start = GetCurrentBoxTime();
- box_time_t end = start + MilliSecondsToBoxTime(Timeout);
int result;
do
{
- box_time_t now = GetCurrentBoxTime();
- result = ::poll(&p, 1, PollTimeout(end - now));
+ result = ::poll(&p, 1, PollTimeout(Timeout, start));
}
while(result == -1 && errno == EINTR);
@@ -337,7 +335,6 @@
// Bytes left to send
int bytesLeft = NBytes;
box_time_t start = GetCurrentBoxTime();
- box_time_t end = start + MilliSecondsToBoxTime(Timeout);
while(bytesLeft > 0)
{
@@ -370,9 +367,7 @@
mSocketHandle << " (" << bytesLeft <<
" of " << NBytes << " bytes left)");
- box_time_t now = GetCurrentBoxTime();
-
- if(!Poll(POLLOUT, PollTimeout(end - now)))
+ if(!Poll(POLLOUT, PollTimeout(Timeout, start)))
{
THROW_EXCEPTION_MESSAGE(ConnectionException,
Protocol_Timeout, "Timed out waiting "
Modified: box/trunk/lib/server/SocketStream.h
===================================================================
--- box/trunk/lib/server/SocketStream.h 2014-08-15 22:48:07 UTC (rev 3370)
+++ box/trunk/lib/server/SocketStream.h 2014-08-15 22:48:10 UTC (rev 3371)
@@ -59,19 +59,33 @@
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);
More information about the Boxbackup-commit
mailing list