#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>
#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
if (noExceptions) {
return false;
} else {
- throw SocketException("Failed to create socket");
+ throw SocketException(std::string("Failed to create socket: error ")
+ + itos(LAST_SOCKET_ERR()));
}
}
class SocketException : public BaseException
{
public:
- SocketException(const char *s):
+ SocketException(const std::string &s):
BaseException(s)
{
}
class ResolveError : public BaseException
{
public:
- ResolveError(const char *s):
+ ResolveError(const std::string &s):
BaseException(s)
{
}
class SendFailedException : public BaseException
{
public:
- SendFailedException(const char *s):
+ SendFailedException(const std::string &s):
BaseException(s)
{
}