[Box Backup-commit] COMMIT r1086 - box/chris/merge/lib/server

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Tue Oct 17 00:21:00 BST 2006


Author: chris
Date: 2006-10-17 00:20:59 +0100 (Tue, 17 Oct 2006)
New Revision: 1086

Modified:
   box/chris/merge/lib/server/SocketStreamTLS.cpp
Log:
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)


Modified: box/chris/merge/lib/server/SocketStreamTLS.cpp
===================================================================
--- box/chris/merge/lib/server/SocketStreamTLS.cpp	2006-10-16 23:20:01 UTC (rev 1085)
+++ box/chris/merge/lib/server/SocketStreamTLS.cpp	2006-10-16 23:20:59 UTC (rev 1086)
@@ -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