[Box Backup-commit] COMMIT r971 - box/chris/general/lib/server

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Wed Oct 11 22:58:41 BST 2006


Author: chris
Date: 2006-10-11 22:58:41 +0100 (Wed, 11 Oct 2006)
New Revision: 971

Modified:
   box/chris/general/lib/server/SocketStreamTLS.cpp
Log:
- More accurate timing (avoids spin loops of zero wait during the last
  second of polling)


Modified: box/chris/general/lib/server/SocketStreamTLS.cpp
===================================================================
--- box/chris/general/lib/server/SocketStreamTLS.cpp	2006-10-11 21:58:01 UTC (rev 970)
+++ box/chris/general/lib/server/SocketStreamTLS.cpp	2006-10-11 21:58:41 UTC (rev 971)
@@ -23,6 +23,7 @@
 #include "SSLLib.h"
 #include "ServerException.h"
 #include "TLSContext.h"
+#include "BoxTime.h"
 
 #include "MemLeakFindOn.h"
 
@@ -244,20 +245,30 @@
 		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)
+		int64_t now = BoxTimeToMilliSeconds(GetCurrentBoxTime());
+		int poll_timeout = (int)(end - now);
+		if (poll_timeout < 0) poll_timeout = 0;
+		if (Timeout == IOStream::TimeOutInfinite)
 		{
-			// Signal. Do "time out"
-			return false;
+			poll_timeout = INFTIM;
 		}
-		else
-		{
-			// Bad!
-			THROW_EXCEPTION(ServerException, SocketPollError)
-		}
+		result = ::poll(&p, 1, poll_timeout);
+	}
+	while(result == -1 && errno == EINTR);
+
+	switch(result)
+	{
+	case -1:
+		// error - Bad!
+		THROW_EXCEPTION(ServerException, SocketPollError)
 		break;
 
 	case 0:




More information about the Boxbackup-commit mailing list