diff options
-rw-r--r-- | lib/common/Logging.h | 12 | ||||
-rw-r--r-- | lib/server/SocketStream.cpp | 26 |
2 files changed, 22 insertions, 16 deletions
diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 26199701..856c0499 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -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) \ diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index a035898d..edb5e5b8 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -176,25 +176,31 @@ void SocketStream::Open(Socket::Type Type, const std::string& rName, int Port) 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 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(); |