diff options
author | Adam <Adam@anope.org> | 2013-07-03 17:26:45 -0400 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-07-14 20:23:53 +0200 |
commit | 6e0b904d342461cd2ac2a3cd0cf2a43d864d2b00 (patch) | |
tree | 980eb8923398714aeef820d0bb6b719f3b149837 /src/socketengine.cpp | |
parent | 2a9aa9be8ac4a97ce766c797aff76abf135bb139 (diff) |
Use the correct socket related error messages on Windows
Diffstat (limited to 'src/socketengine.cpp')
-rw-r--r-- | src/socketengine.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 6c99edc95..8af598b06 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -255,3 +255,26 @@ void SocketEngine::GetStats(float &kbitpersec_in, float &kbitpersec_out, float & kbitpersec_in = in_kbit / 1024; kbitpersec_out = out_kbit / 1024; } + +std::string SocketEngine::LastError() +{ +#ifndef _WIN32 + return strerror(errno); +#else + char szErrorString[500]; + DWORD dwErrorCode = WSAGetLastError(); + if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)szErrorString, _countof(szErrorString), NULL) == 0) + sprintf_s(szErrorString, _countof(szErrorString), "Error code: %u", dwErrorCode); + return szErrorString; +#endif +} + +std::string SocketEngine::GetError(int errnum) +{ +#ifndef _WIN32 + return strerror(errnum); +#else + WSASetLastError(errnum); + return LastError(); +#endif +} |