[Box Backup-commit] COMMIT r3364 - in box/trunk: lib/common lib/compress lib/server test/compress

subversion at boxbackup.org subversion at boxbackup.org
Fri Aug 15 23:47:52 BST 2014


Author: chris
Date: 2014-08-15 23:47:52 +0100 (Fri, 15 Aug 2014)
New Revision: 3364

Modified:
   box/trunk/lib/common/IOStream.cpp
   box/trunk/lib/common/IOStream.h
   box/trunk/lib/compress/CompressStream.cpp
   box/trunk/lib/compress/CompressStream.h
   box/trunk/lib/server/Protocol.cpp
   box/trunk/lib/server/SocketStreamTLS.cpp
   box/trunk/test/compress/testcompress.cpp
Log:
Add missing timeouts for network operations.

Modified: box/trunk/lib/common/IOStream.cpp
===================================================================
--- box/trunk/lib/common/IOStream.cpp	2014-08-15 22:47:50 UTC (rev 3363)
+++ box/trunk/lib/common/IOStream.cpp	2014-08-15 22:47:52 UTC (rev 3364)
@@ -165,7 +165,7 @@
 //		Created: 2003/08/26
 //
 // --------------------------------------------------------------------------
-void IOStream::WriteAllBuffered()
+void IOStream::WriteAllBuffered(int Timeout)
 {
 }
 

Modified: box/trunk/lib/common/IOStream.h
===================================================================
--- box/trunk/lib/common/IOStream.h	2014-08-15 22:47:50 UTC (rev 3363)
+++ box/trunk/lib/common/IOStream.h	2014-08-15 22:47:52 UTC (rev 3364)
@@ -50,7 +50,7 @@
 	virtual void Write(const void *pBuffer, int NBytes,
 		int Timeout = IOStream::TimeOutInfinite) = 0;
 	virtual void Write(const char *pBuffer);
-	virtual void WriteAllBuffered();
+	virtual void WriteAllBuffered(int Timeout = IOStream::TimeOutInfinite);
 	virtual pos_type GetPosition() const;
 	virtual void Seek(pos_type Offset, int SeekType);
 	virtual void Close();

Modified: box/trunk/lib/compress/CompressStream.cpp
===================================================================
--- box/trunk/lib/compress/CompressStream.cpp	2014-08-15 22:47:50 UTC (rev 3363)
+++ box/trunk/lib/compress/CompressStream.cpp	2014-08-15 22:47:52 UTC (rev 3364)
@@ -177,12 +177,12 @@
 //		Created: 27/5/04
 //
 // --------------------------------------------------------------------------
-void CompressStream::Write(const void *pBuffer, int NBytes)
+void CompressStream::Write(const void *pBuffer, int NBytes, int Timeout)
 {
 	USE_WRITE_COMPRESSOR
 	if(pCompress == 0)
 	{
-		mpStream->Write(pBuffer, NBytes);
+		mpStream->Write(pBuffer, NBytes, Timeout);
 		return;
 	}
 	
@@ -207,7 +207,7 @@
 //		Created: 27/5/04
 //
 // --------------------------------------------------------------------------
-void CompressStream::WriteAllBuffered()
+void CompressStream::WriteAllBuffered(int Timeout)
 {
 	if(mIsClosed)
 	{
@@ -215,7 +215,7 @@
 	}
 
 	// Just ask compressed data to be written out, but with the sync flag set
-	WriteCompressedData(true);
+	WriteCompressedData(true, Timeout);
 }
 
 
@@ -238,7 +238,7 @@
 			pCompress->FinishInput();
 			WriteCompressedData();
 			
-			// Mark as definately closed
+			// Mark as definitely closed
 			mIsClosed = true;
 		}
 	}
@@ -257,7 +257,7 @@
 //		Created: 28/5/04
 //
 // --------------------------------------------------------------------------
-void CompressStream::WriteCompressedData(bool SyncFlush)
+void CompressStream::WriteCompressedData(bool SyncFlush, int Timeout)
 {
 	USE_WRITE_COMPRESSOR
 	if(pCompress == 0) {THROW_EXCEPTION(CompressException, Internal)}
@@ -268,7 +268,7 @@
 		s = pCompress->Output(mpBuffer, BUFFER_SIZE, SyncFlush);
 		if(s > 0)
 		{
-			mpStream->Write(mpBuffer, s);
+			mpStream->Write(mpBuffer, s, Timeout);
 		}
 	} while(s > 0);
 	// Check assumption -- all input has been consumed

Modified: box/trunk/lib/compress/CompressStream.h
===================================================================
--- box/trunk/lib/compress/CompressStream.h	2014-08-15 22:47:50 UTC (rev 3363)
+++ box/trunk/lib/compress/CompressStream.h	2014-08-15 22:47:52 UTC (rev 3364)
@@ -33,8 +33,9 @@
 public:
 
 	virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
-	virtual void Write(const void *pBuffer, int NBytes);
-	virtual void WriteAllBuffered();
+	virtual void Write(const void *pBuffer, int NBytes,
+		int Timeout = IOStream::TimeOutInfinite);
+	virtual void WriteAllBuffered(int Timeout = IOStream::TimeOutInfinite);
 	virtual void Close();
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
@@ -43,7 +44,8 @@
 	void CheckRead();
 	void CheckWrite();
 	void CheckBuffer();
-	void WriteCompressedData(bool SyncFlush = false);
+	void WriteCompressedData(bool SyncFlush = false,
+		int Timeout = IOStream::TimeOutInfinite);
 
 private:
 	IOStream *mpStream;

Modified: box/trunk/lib/server/Protocol.cpp
===================================================================
--- box/trunk/lib/server/Protocol.cpp	2014-08-15 22:47:50 UTC (rev 3363)
+++ box/trunk/lib/server/Protocol.cpp	2014-08-15 22:47:52 UTC (rev 3364)
@@ -104,7 +104,7 @@
 	::strncpy(hsSend.mIdent, GetProtocolIdentString(), sizeof(hsSend.mIdent));
 	
 	// Send it
-	mapConn->Write(&hsSend, sizeof(hsSend));
+	mapConn->Write(&hsSend, sizeof(hsSend), GetTimeout());
 	mapConn->WriteAllBuffered();
 
 	// Receive a handshake from the peer
@@ -115,7 +115,7 @@
 	while(bytesToRead > 0)
 	{
 		// Get some data from the stream
-		int bytesRead = mapConn->Read(readInto, bytesToRead, mTimeout);
+		int bytesRead = mapConn->Read(readInto, bytesToRead, GetTimeout());
 		if(bytesRead == 0)
 		{
 			THROW_EXCEPTION(ConnectionException, Protocol_Timeout)
@@ -296,7 +296,7 @@
 	pobjHeader->mObjType = htonl(rObject.GetType());
 
 	// Write data
-	mapConn->Write(mpBuffer, writtenSize);
+	mapConn->Write(mpBuffer, writtenSize, GetTimeout());
 	mapConn->WriteAllBuffered();
 }
 
@@ -713,7 +713,7 @@
 	objHeader.mObjType = htonl(SPECIAL_STREAM_OBJECT_TYPE);
 
 	// Write header
-	mapConn->Write(&objHeader, sizeof(objHeader));
+	mapConn->Write(&objHeader, sizeof(objHeader), GetTimeout());
 	// Could be sent in one of two ways
 	if(uncertainSize)
 	{
@@ -748,7 +748,7 @@
 			// Send final byte to finish the stream
 			BOX_TRACE("Sending end of stream byte");
 			uint8_t endOfStream = ProtocolStreamHeader_EndOfStream;
-			mapConn->Write(&endOfStream, 1);
+			mapConn->Write(&endOfStream, 1, GetTimeout());
 			BOX_TRACE("Sent end of stream byte");
 		}
 		catch(...)
@@ -763,7 +763,8 @@
 	else
 	{
 		// Fixed size stream, send it all in one go
-		if(!rStream.CopyStreamTo(*mapConn, mTimeout, 4096 /* slightly larger buffer */))
+		if(!rStream.CopyStreamTo(*mapConn, GetTimeout(),
+			4096 /* slightly larger buffer */))
 		{
 			THROW_EXCEPTION(ConnectionException, Protocol_TimeOutWhenSendingStream)
 		}
@@ -820,7 +821,7 @@
 	Block[-1] = header;
 	
 	// Write everything out
-	mapConn->Write(Block - 1, writeSize + 1);
+	mapConn->Write(Block - 1, writeSize + 1, GetTimeout());
 	
 	BOX_TRACE("Sent " << (writeSize+1) << " bytes to stream");
 	// move the remainer to the beginning of the block for the next time round

Modified: box/trunk/lib/server/SocketStreamTLS.cpp
===================================================================
--- box/trunk/lib/server/SocketStreamTLS.cpp	2014-08-15 22:47:50 UTC (rev 3363)
+++ box/trunk/lib/server/SocketStreamTLS.cpp	2014-08-15 22:47:52 UTC (rev 3364)
@@ -356,12 +356,12 @@
 
 		case SSL_ERROR_WANT_READ:
 		case SSL_ERROR_WANT_WRITE:
-			// wait for the requried data
+			// wait for the required data
 			{
 			#ifndef BOX_RELEASE_BUILD
-				bool conditionmet = 
+				bool conditionmet =
 			#endif
-				WaitWhenRetryRequired(se, IOStream::TimeOutInfinite);
+				WaitWhenRetryRequired(se, Timeout);
 				ASSERT(conditionmet);
 			}
 			break;

Modified: box/trunk/test/compress/testcompress.cpp
===================================================================
--- box/trunk/test/compress/testcompress.cpp	2014-08-15 22:47:50 UTC (rev 3363)
+++ box/trunk/test/compress/testcompress.cpp	2014-08-15 22:47:52 UTC (rev 3364)
@@ -47,9 +47,10 @@
 
 		return 0;
 	}
-	void Write(const void *pBuffer, int NBytes)
+	void Write(const void *pBuffer, int NBytes,
+		int Timeout = IOStream::TimeOutInfinite)
 	{
-		buffers[(currentBuffer + 1) & 1].Write(pBuffer, NBytes);
+		buffers[(currentBuffer + 1) & 1].Write(pBuffer, NBytes, Timeout);
 	}
 	bool StreamDataLeft()
 	{




More information about the Boxbackup-commit mailing list