X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fsocket.cpp;h=17fa1924dd217491ad308daa777866bf1747a2b6;hb=c26eb87aec7438d167fa2f460a3f412db09c0ac5;hp=df9c57c5f9223a06d511e83e2b2e1551ebd706dd;hpb=209c0dd1af7b1b26fbaa4bc36e8c57f755fb222b;p=oweals%2Fminetest.git diff --git a/src/socket.cpp b/src/socket.cpp index df9c57c5f..17fa1924d 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -32,7 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "debug.h" #include "settings.h" #include "log.h" -#include "main.h" // for g_settings #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -45,11 +44,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include - #ifdef _MSC_VER - #pragma comment(lib, "ws2_32.lib") - #endif -typedef SOCKET socket_t; -typedef int socklen_t; + #define LAST_SOCKET_ERR() WSAGetLastError() + typedef SOCKET socket_t; + typedef int socklen_t; #else #include #include @@ -58,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 @@ -155,7 +153,7 @@ void Address::Resolve(const char *name) struct addrinfo *resolved, hints; memset(&hints, 0, sizeof(hints)); - + // Setup hints hints.ai_socktype = 0; hints.ai_protocol = 0; @@ -169,7 +167,7 @@ void Address::Resolve(const char *name) { hints.ai_family = AF_INET; } - + // Do getaddrinfo() int e = getaddrinfo(name, NULL, &hints, &resolved); if(e != 0) @@ -343,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())); } } @@ -515,7 +514,7 @@ int UDPSocket::Receive(Address & sender, void *data, int size) dstream << (int) m_handle << " <- "; sender.print(&dstream); dstream << ", size=" << received; - + // Print packet contents dstream << ", data="; for(int i = 0; i < received && i < 20; i++) { @@ -526,7 +525,7 @@ int UDPSocket::Receive(Address & sender, void *data, int size) } if(received > 20) dstream << "..."; - + dstream << std::endl; } @@ -575,9 +574,8 @@ bool UDPSocket::WaitData(int timeout_ms) int e = WSAGetLastError(); dstream << (int) m_handle << ": WSAGetLastError()=" << e << std::endl; - if(e == 10004 /* = WSAEINTR */ || e == 10009 /*WSAEBADF*/) - { - dstream << "WARNING: Ignoring WSAEINTR/WSAEBADF." << std::endl; + if (e == 10004 /* WSAEINTR */ || e == 10009 /* WSAEBADF */) { + infostream << "Ignoring WSAEINTR/WSAEBADF." << std::endl; return false; } #endif @@ -587,7 +585,7 @@ bool UDPSocket::WaitData(int timeout_ms) // No data return false; } - + // There is data return true; }