From 88a3977954f537b391c714be2a52da6b19711154 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sun, 8 Nov 2015 18:14:36 -0500 Subject: [PATCH] Add errno to socket creation failed exception --- src/socket.cpp | 11 +++++++---- src/socket.h | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/socket.cpp b/src/socket.cpp index 47fffcc4d..17fa1924d 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -44,8 +44,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -typedef SOCKET socket_t; -typedef int socklen_t; + #define LAST_SOCKET_ERR() WSAGetLastError() + typedef SOCKET socket_t; + typedef int socklen_t; #else #include #include @@ -54,7 +55,8 @@ typedef int socklen_t; #include #include #include -typedef int socket_t; + #define LAST_SOCKET_ERR() (errno) + typedef int socket_t; #endif // Set to true to enable verbose debug output @@ -339,7 +341,8 @@ bool UDPSocket::init(bool ipv6, bool noExceptions) if (noExceptions) { return false; } else { - throw SocketException("Failed to create socket"); + throw SocketException(std::string("Failed to create socket: error ") + + itos(LAST_SOCKET_ERR())); } } diff --git a/src/socket.h b/src/socket.h index c7dd78f66..8d1ad70ff 100644 --- a/src/socket.h +++ b/src/socket.h @@ -45,7 +45,7 @@ extern bool socket_enable_debug_output; class SocketException : public BaseException { public: - SocketException(const char *s): + SocketException(const std::string &s): BaseException(s) { } @@ -54,7 +54,7 @@ public: class ResolveError : public BaseException { public: - ResolveError(const char *s): + ResolveError(const std::string &s): BaseException(s) { } @@ -63,7 +63,7 @@ public: class SendFailedException : public BaseException { public: - SendFailedException(const char *s): + SendFailedException(const std::string &s): BaseException(s) { }