]> git.lizzy.rs Git - minetest.git/commitdiff
Add errno to socket creation failed exception
authorkwolekr <kwolekr@minetest.net>
Sun, 8 Nov 2015 23:14:36 +0000 (18:14 -0500)
committerkwolekr <kwolekr@minetest.net>
Sun, 8 Nov 2015 23:16:02 +0000 (18:16 -0500)
src/socket.cpp
src/socket.h

index 47fffcc4ddbf3a4661733a0e584871e75f1ce288..17fa1924dd217491ad308daa777866bf1747a2b6 100644 (file)
@@ -44,8 +44,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        #include <windows.h>
        #include <winsock2.h>
        #include <ws2tcpip.h>
-typedef SOCKET socket_t;
-typedef int socklen_t;
+       #define LAST_SOCKET_ERR() WSAGetLastError()
+       typedef SOCKET socket_t;
+       typedef int socklen_t;
 #else
        #include <sys/types.h>
        #include <sys/socket.h>
@@ -54,7 +55,8 @@ typedef int socklen_t;
        #include <netdb.h>
        #include <unistd.h>
        #include <arpa/inet.h>
-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()));
                }
        }
 
index c7dd78f66f8c8602491e486fe2e0ad543372e17d..8d1ad70fff2d3603f6e2c5fee044578dd1cc25ff 100644 (file)
@@ -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 @@ class SocketException : public BaseException
 class ResolveError : public BaseException
 {
 public:
-       ResolveError(const char *s):
+       ResolveError(const std::string &s):
                BaseException(s)
        {
        }
@@ -63,7 +63,7 @@ class ResolveError : public BaseException
 class SendFailedException : public BaseException
 {
 public:
-       SendFailedException(const char *s):
+       SendFailedException(const std::string &s):
                BaseException(s)
        {
        }