summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-06 12:53:01 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-06 12:53:01 +0100
commitf2343ad81b9f8f38452f45e70963bca93a1c03e4 (patch)
tree5fd57d44b61b5a86f246e99a6fe17c5d05fcae01 /source
parentNow showing proper error messages when sockets fail :) (diff)
downloadcuberite-f2343ad81b9f8f38452f45e70963bca93a1c03e4.tar
cuberite-f2343ad81b9f8f38452f45e70963bca93a1c03e4.tar.gz
cuberite-f2343ad81b9f8f38452f45e70963bca93a1c03e4.tar.bz2
cuberite-f2343ad81b9f8f38452f45e70963bca93a1c03e4.tar.lz
cuberite-f2343ad81b9f8f38452f45e70963bca93a1c03e4.tar.xz
cuberite-f2343ad81b9f8f38452f45e70963bca93a1c03e4.tar.zst
cuberite-f2343ad81b9f8f38452f45e70963bca93a1c03e4.zip
Diffstat (limited to 'source')
-rw-r--r--source/cSocket.cpp33
-rw-r--r--source/cSocket.h7
2 files changed, 15 insertions, 25 deletions
diff --git a/source/cSocket.cpp b/source/cSocket.cpp
index f8b0bed20..bb6f68249 100644
--- a/source/cSocket.cpp
+++ b/source/cSocket.cpp
@@ -94,30 +94,14 @@ void cSocket::CloseSocket()
AString cSocket::GetErrorString( int a_ErrNo )
{
-#define CASE_AND_RETURN(x) case x: return #x
+ #ifdef _WIN32
+
+ char Buffer[1024];
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, Buffer, ARRAYCOUNT(Buffer), NULL);
+ return AString(Buffer);
+
+ #else // _WIN32
-#ifdef _WIN32
- switch (WSAGetLastError())
- {
- CASE_AND_RETURN(WSANOTINITIALISED);
- CASE_AND_RETURN(WSAENETDOWN);
- CASE_AND_RETURN(WSAEFAULT);
- CASE_AND_RETURN(WSAENOTCONN);
- CASE_AND_RETURN(WSAEINTR);
- CASE_AND_RETURN(WSAEINPROGRESS);
- CASE_AND_RETURN(WSAENETRESET);
- CASE_AND_RETURN(WSAENOTSOCK);
- CASE_AND_RETURN(WSAEOPNOTSUPP);
- CASE_AND_RETURN(WSAESHUTDOWN);
- CASE_AND_RETURN(WSAEWOULDBLOCK);
- CASE_AND_RETURN(WSAEMSGSIZE);
- CASE_AND_RETURN(WSAEINVAL);
- CASE_AND_RETURN(WSAECONNABORTED);
- CASE_AND_RETURN(WSAETIMEDOUT);
- CASE_AND_RETURN(WSAECONNRESET);
- }
- return "No Error";
-#else
char buffer[ 256 ];
if( strerror_r( errno, buffer, 256 ) == 0 )
{
@@ -127,7 +111,8 @@ AString cSocket::GetErrorString( int a_ErrNo )
{
return "Error on getting error string!";
}
-#endif
+
+ #endif // else _WIN32
}
diff --git a/source/cSocket.h b/source/cSocket.h
index 98fc5fdc4..81408c918 100644
--- a/source/cSocket.h
+++ b/source/cSocket.h
@@ -29,7 +29,12 @@ public:
static int WSAStartup();
static AString GetErrorString( int a_ErrNo );
- static int GetLastError();
+ static int GetLastError();
+ static AString GetLastErrorString(void)
+ {
+ return GetErrorString(GetLastError());
+ }
+
static cSocket CreateSocket();
inline static bool IsSocketError( int a_ReturnedValue )