From b92b80f5216c9f56bb7ffc349851e07db251b1e0 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 22 Jan 2012 16:26:38 +0000 Subject: Remove unnecessary GetNativeErrorMessage(), add BOX_LOG_SOCKET_ERROR macro. --- lib/common/Logging.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/common/Logging.h b/lib/common/Logging.h index b1301743..4ddf760d 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -82,17 +82,6 @@ THROW_EXCEPTION_MESSAGE(exception, subtype, \ BOX_FILE_MESSAGE(filename, message)) -inline std::string GetNativeErrorMessage() -{ -#ifdef WIN32 - return GetErrorMessage(GetLastError()); -#else - std::ostringstream _box_log_line; - _box_log_line << std::strerror(errno) << " (" << errno << ")"; - return _box_log_line.str(); -#endif -} - #ifdef WIN32 #define BOX_LOG_WIN_ERROR(stuff) \ BOX_ERROR(stuff << ": " << GetErrorMessage(GetLastError())) @@ -105,21 +94,30 @@ inline std::string GetNativeErrorMessage() #define BOX_LOG_NATIVE_ERROR(stuff) BOX_LOG_WIN_ERROR(stuff) #define BOX_LOG_NATIVE_WARNING(stuff) BOX_LOG_WIN_WARNING(stuff) #define BOX_WIN_ERRNO_MESSAGE(error_number, stuff) \ - stuff << ": " << GetErrorMessage(error_number) << " (" << error_number << ")" + stuff << ": " << GetErrorMessage(error_number) #define THROW_WIN_ERROR_NUMBER(message, error_number, exception, subtype) \ THROW_EXCEPTION_MESSAGE(exception, subtype, \ BOX_WIN_ERRNO_MESSAGE(error_number, message)) #define THROW_WIN_FILE_ERRNO(message, filename, error_number, exception, subtype) \ THROW_WIN_ERROR_NUMBER(BOX_FILE_MESSAGE(filename, message), \ error_number, exception, subtype) + #define THROW_WIN_FILE_ERROR(message, filename, exception, subtype) \ + THROW_WIN_FILE_ERRNO(message, filename, GetLastError(), \ + exception, subtype) #else #define BOX_LOG_NATIVE_ERROR(stuff) BOX_LOG_SYS_ERROR(stuff) #define BOX_LOG_NATIVE_WARNING(stuff) BOX_LOG_SYS_WARNING(stuff) #endif -#define BOX_LOG_SOCKET_ERROR(_type, _name, _port, stuff) \ +#ifdef WIN32 +# define BOX_LOG_SOCKET_ERROR(_type, _name, _port, stuff) \ + BOX_LOG_WIN_ERROR_NUMBER(stuff << " (type " << _type << ", name " << \ + _name << ", port " << _port << ")", WSAGetLastError()) +#else +# define BOX_LOG_SOCKET_ERROR(_type, _name, _port, stuff) \ BOX_LOG_NATIVE_ERROR(stuff << " (type " << _type << ", name " << \ _name << ", port " << _port << ")") +#endif #define BOX_FORMAT_HEX32(number) \ std::hex << \ -- cgit v1.2.3