[Box Backup-commit] COMMIT r3503 - in box/trunk: bin/bbackupd lib/server

subversion at boxbackup.org subversion at boxbackup.org
Sun Dec 28 22:03:24 GMT 2014


Author: chris
Date: 2014-12-28 22:03:23 +0000 (Sun, 28 Dec 2014)
New Revision: 3503

Modified:
   box/trunk/bin/bbackupd/BackupDaemon.cpp
   box/trunk/lib/server/SocketStream.h
   box/trunk/lib/server/WinNamedPipeStream.h
Log:
Add missing timeouts on command socket writes.

Modified: box/trunk/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-12-26 23:17:12 UTC (rev 3502)
+++ box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-12-28 22:03:23 UTC (rev 3503)
@@ -2062,7 +2062,7 @@
 						conf.GetKeyValueInt("MaxUploadWait") 
 						<< "\nstate " << mState << "\n";
 					mapCommandSocketInfo->mpConnectedSocket->Write(
-						hello.str());
+						hello.str(), timeout);
 					
 					// Set the timeout to something very small, so we don't wait too long on waiting
 					// for any incoming data
@@ -2082,7 +2082,8 @@
 		}
 		
 		// Ping the remote side, to provide errors which will mean the socket gets closed
-		mapCommandSocketInfo->mpConnectedSocket->Write("ping\n", 5);
+		mapCommandSocketInfo->mpConnectedSocket->Write("ping\n", 5,
+			timeout);
 		
 		// Wait for a command or something on the socket
 		std::string command;
@@ -2132,7 +2133,9 @@
 			// Send a response back?
 			if(sendResponse)
 			{
-				mapCommandSocketInfo->mpConnectedSocket->Write(sendOK?"ok\n":"error\n", sendOK?3:6);
+				std::string response = sendOK ? "ok\n" : "error\n";
+				mapCommandSocketInfo->mpConnectedSocket->Write(
+					response, timeout);
 			}
 			
 			// Set timeout to something very small, so this just checks for data which is waiting
@@ -2257,8 +2260,8 @@
 		try
 		{
 			message += "\n";
-			mapCommandSocketInfo->mpConnectedSocket->Write(
-				message.c_str(), message.size());
+			mapCommandSocketInfo->mpConnectedSocket->Write(message,
+				1); // short timeout, it's overlapped
 		}
 		catch(std::exception &e)
 		{
@@ -2989,7 +2992,8 @@
 	// Something connected to the command socket, tell it about the new state
 	try
 	{
-		mapCommandSocketInfo->mpConnectedSocket->Write(msg.str());
+		mapCommandSocketInfo->mpConnectedSocket->Write(msg.str(),
+			1); // very short timeout, it's overlapped anyway
 	}
 	catch(ConnectionException &ce)
 	{

Modified: box/trunk/lib/server/SocketStream.h
===================================================================
--- box/trunk/lib/server/SocketStream.h	2014-12-26 23:17:12 UTC (rev 3502)
+++ box/trunk/lib/server/SocketStream.h	2014-12-28 22:03:23 UTC (rev 3503)
@@ -51,9 +51,9 @@
 	virtual void Write(const void *pBuffer, int NBytes,
 		int Timeout = IOStream::TimeOutInfinite);
 
-	// Why not inherited from IOStream?
-	virtual void Write(const std::string& rBuffer,
-		int Timeout = IOStream::TimeOutInfinite)
+	// Why not inherited from IOStream? Never mind, we want to enforce
+	// supplying a timeout for network operations anyway.
+	virtual void Write(const std::string& rBuffer, int Timeout)
 	{
 		IOStream::Write(rBuffer, Timeout);
 	}

Modified: box/trunk/lib/server/WinNamedPipeStream.h
===================================================================
--- box/trunk/lib/server/WinNamedPipeStream.h	2014-12-26 23:17:12 UTC (rev 3502)
+++ box/trunk/lib/server/WinNamedPipeStream.h	2014-12-28 22:03:23 UTC (rev 3503)
@@ -45,9 +45,9 @@
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 
-	// Why not inherited from IOStream?
-	virtual void Write(const std::string& rBuffer,
-		int Timeout = IOStream::TimeOutInfinite)
+	// Why not inherited from IOStream? Never mind, we want to enforce
+	// supplying a timeout for network operations anyway.
+	virtual void Write(const std::string& rBuffer, int Timeout)
 	{
 		IOStream::Write(rBuffer, Timeout);
 	}




More information about the Boxbackup-commit mailing list