[Box Backup-commit] COMMIT r3554 - in box/trunk/lib: common server

subversion at boxbackup.org subversion at boxbackup.org
Wed Apr 15 23:03:00 BST 2015


Author: chris
Date: 2015-04-15 22:03:00 +0000 (Wed, 15 Apr 2015)
New Revision: 3554

Modified:
   box/trunk/lib/common/Logging.h
   box/trunk/lib/server/SocketStream.cpp
Log:
Define BOX_SOCKET_ERROR_MESSAGE, replace more BOX_LOG_SOCKET_ERROR calls with it.

Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h	2015-04-15 22:02:54 UTC (rev 3553)
+++ box/trunk/lib/common/Logging.h	2015-04-15 22:03:00 UTC (rev 3554)
@@ -139,13 +139,13 @@
 		exception, subtype)
 
 #ifdef WIN32
-#	define BOX_LOG_SOCKET_ERROR(_type, _name, _port, stuff) \
-	BOX_LOG_WIN_ERROR_NUMBER(stuff << " (type " << _type << ", name " << \
-		_name << ", port " << _port << ")", WSAGetLastError())
+#	define BOX_SOCKET_ERROR_MESSAGE(_type, _name, _port, stuff) \
+	BOX_WIN_ERRNO_MESSAGE(WSAGetLastError(), stuff << " (type " << _type << \
+		", name " << _name << ", port " << _port << ")")
 #else
-#	define BOX_LOG_SOCKET_ERROR(_type, _name, _port, stuff) \
-	BOX_LOG_NATIVE_ERROR(stuff << " (type " << _type << ", name " << \
-		_name << ", port " << _port << ")")
+#	define BOX_SOCKET_ERROR_MESSAGE(_type, _name, _port, stuff) \
+	BOX_SYS_ERROR_MESSAGE(stuff << " (type " << _type << ", name " << _name << \
+		", port " << _port << ")")
 #endif
 
 #define BOX_FORMAT_HEX32(number) \

Modified: box/trunk/lib/server/SocketStream.cpp
===================================================================
--- box/trunk/lib/server/SocketStream.cpp	2015-04-15 22:02:54 UTC (rev 3553)
+++ box/trunk/lib/server/SocketStream.cpp	2015-04-15 22:03:00 UTC (rev 3554)
@@ -176,9 +176,9 @@
 		0 /* let OS choose protocol */);
 	if(mSocketHandle == INVALID_SOCKET_VALUE)
 	{
-		BOX_LOG_SOCKET_ERROR(Type, rName, Port,
-			"Failed to create a network socket");
-		THROW_EXCEPTION(ServerException, SocketOpenError)
+		THROW_EXCEPTION_MESSAGE(ServerException, SocketOpenError,
+			BOX_SOCKET_ERROR_MESSAGE(Type, rName, Port,
+			"Failed to create a network socket"));
 	}
 	
 	// Connect it
@@ -185,16 +185,22 @@
 	if(::connect(mSocketHandle, &addr.sa_generic, addrLen) == -1)
 	{
 		// Dispose of the socket
-		BOX_LOG_SOCKET_ERROR(Type, rName, Port,
-			"Failed to connect to socket");
+		try
+		{
+			THROW_EXCEPTION_MESSAGE(ServerException, SocketOpenError,
+				BOX_SOCKET_ERROR_MESSAGE(Type, rName, Port,
+				"Failed to connect to socket"));
+		}
+		catch(ServerException &e)
+		{
 #ifdef WIN32
-		::closesocket(mSocketHandle);
+			::closesocket(mSocketHandle);
 #else // !WIN32
-		::close(mSocketHandle);
+			::close(mSocketHandle);
 #endif // WIN32
-
-		mSocketHandle = INVALID_SOCKET_VALUE;
-		THROW_EXCEPTION(ConnectionException, SocketConnectError)
+			mSocketHandle = INVALID_SOCKET_VALUE;
+			throw;
+		}
 	}
 
 	ResetCounters();




More information about the Boxbackup-commit mailing list