diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-05 17:24:16 +0100 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-05 17:24:16 +0100 |
commit | ab95abb6bde0073ebb869624332adf028aac8dd7 (patch) | |
tree | 74df0d744fafb12719d3e3934e9d1bfbbb20e72f /source/cSocket.cpp | |
parent | cSocket: added error logging to Bind() failures (diff) | |
download | cuberite-ab95abb6bde0073ebb869624332adf028aac8dd7.tar cuberite-ab95abb6bde0073ebb869624332adf028aac8dd7.tar.gz cuberite-ab95abb6bde0073ebb869624332adf028aac8dd7.tar.bz2 cuberite-ab95abb6bde0073ebb869624332adf028aac8dd7.tar.lz cuberite-ab95abb6bde0073ebb869624332adf028aac8dd7.tar.xz cuberite-ab95abb6bde0073ebb869624332adf028aac8dd7.tar.zst cuberite-ab95abb6bde0073ebb869624332adf028aac8dd7.zip |
Diffstat (limited to 'source/cSocket.cpp')
-rw-r--r-- | source/cSocket.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/source/cSocket.cpp b/source/cSocket.cpp index 10ccec3c3..f8b0bed20 100644 --- a/source/cSocket.cpp +++ b/source/cSocket.cpp @@ -92,7 +92,7 @@ void cSocket::CloseSocket() -const char * cSocket::GetLastErrorString()
+AString cSocket::GetErrorString( int a_ErrNo )
{
#define CASE_AND_RETURN(x) case x: return #x
@@ -118,7 +118,27 @@ const char * cSocket::GetLastErrorString() }
return "No Error";
#else
- return "GetLastErrorString() only works on Windows";
+ char buffer[ 256 ];
+ if( strerror_r( errno, buffer, 256 ) == 0 )
+ {
+ return AString( buffer );
+ }
+ else
+ {
+ return "Error on getting error string!";
+ }
+#endif
+}
+
+
+
+
+int cSocket::GetLastError()
+{
+#ifdef _WIN32
+ return WSAGetLastError();
+#else
+ return errno;
#endif
}
@@ -176,16 +196,7 @@ int cSocket::Bind(SockAddr_In& a_Address) local.sin_port=htons((u_short)a_Address.Port);
- int res = bind(m_Socket, (sockaddr*)&local, sizeof(local));
- if (res != 0)
- {
- #ifdef _WIN32
- LOGWARNING("bind() failed for port %d, WSAGLE = %d", a_Address.Port, WSAGetLastError());
- #else // _WIN32
- LOGWARNING("bind() failed for port %d, errno = %d", a_Address.Port, errno);
- #endif // else _WIN32
- }
- return res;
+ return bind(m_Socket, (sockaddr*)&local, sizeof(local));
}
|