cSocket: re-implemented the GetLastErrorString() function; win: error texts are now queried from the system rather than enumerated by the program
git-svn-id: http://mc-server.googlecode.com/svn/trunk@235 0a769ca7-a7f5-676a-18bf-c427514a06d6master
parent
ab95abb6bd
commit
f2343ad81b
|
@ -94,30 +94,14 @@ void cSocket::CloseSocket()
|
||||||
|
|
||||||
AString cSocket::GetErrorString( int a_ErrNo )
|
AString cSocket::GetErrorString( int a_ErrNo )
|
||||||
{
|
{
|
||||||
#define CASE_AND_RETURN(x) case x: return #x
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
switch (WSAGetLastError())
|
|
||||||
{
|
char Buffer[1024];
|
||||||
CASE_AND_RETURN(WSANOTINITIALISED);
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, Buffer, ARRAYCOUNT(Buffer), NULL);
|
||||||
CASE_AND_RETURN(WSAENETDOWN);
|
return AString(Buffer);
|
||||||
CASE_AND_RETURN(WSAEFAULT);
|
|
||||||
CASE_AND_RETURN(WSAENOTCONN);
|
#else // _WIN32
|
||||||
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 ];
|
char buffer[ 256 ];
|
||||||
if( strerror_r( errno, buffer, 256 ) == 0 )
|
if( strerror_r( errno, buffer, 256 ) == 0 )
|
||||||
{
|
{
|
||||||
|
@ -127,7 +111,8 @@ AString cSocket::GetErrorString( int a_ErrNo )
|
||||||
{
|
{
|
||||||
return "Error on getting error string!";
|
return "Error on getting error string!";
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // else _WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,11 @@ public:
|
||||||
|
|
||||||
static AString GetErrorString( int a_ErrNo );
|
static AString GetErrorString( int a_ErrNo );
|
||||||
static int GetLastError();
|
static int GetLastError();
|
||||||
|
static AString GetLastErrorString(void)
|
||||||
|
{
|
||||||
|
return GetErrorString(GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
static cSocket CreateSocket();
|
static cSocket CreateSocket();
|
||||||
|
|
||||||
inline static bool IsSocketError( int a_ReturnedValue )
|
inline static bool IsSocketError( int a_ReturnedValue )
|
||||||
|
|
Loading…
Reference in New Issue