#include "debug.h"
#include "settings.h"
#include "log.h"
-#include "main.h" // for g_settings
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
- #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 <sys/types.h>
#include <sys/socket.h>
#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
struct addrinfo *resolved, hints;
memset(&hints, 0, sizeof(hints));
-
+
// Setup hints
hints.ai_socktype = 0;
hints.ai_protocol = 0;
{
hints.ai_family = AF_INET;
}
-
+
// Do getaddrinfo()
int e = getaddrinfo(name, NULL, &hints, &resolved);
if(e != 0)
if (noExceptions) {
return false;
} else {
- throw SocketException("Failed to create socket");
+ throw SocketException(std::string("Failed to create socket: error ")
+ + itos(LAST_SOCKET_ERR()));
}
}
dstream << (int) m_handle << " <- ";
sender.print(&dstream);
dstream << ", size=" << received;
-
+
// Print packet contents
dstream << ", data=";
for(int i = 0; i < received && i < 20; i++) {
}
if(received > 20)
dstream << "...";
-
+
dstream << std::endl;
}
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
// No data
return false;
}
-
+
// There is data
return true;
}