mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-25 08:01:02 +02:00
Consolidate Win32-specific error formatting
GetErrorReason()'s Win32 implementation does the same thing as Win32ErrorString(int err) from syserror.cpp, so call the latter. Also remove now-unnecessary headers from sock.cpp and less verbose handling of #ifdefs.
This commit is contained in:
parent
c95a4432d7
commit
5408a55fc8
@ -81,12 +81,7 @@ bool FileLock::TryLock()
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
static std::string GetErrorReason() {
|
static std::string GetErrorReason() {
|
||||||
wchar_t* err;
|
return Win32ErrorString(GetLastError());
|
||||||
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<WCHAR*>(&err), 0, nullptr);
|
|
||||||
std::wstring err_str(err);
|
|
||||||
LocalFree(err);
|
|
||||||
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().to_bytes(err_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileLock::FileLock(const fs::path& file)
|
FileLock::FileLock(const fs::path& file)
|
||||||
|
@ -15,11 +15,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <codecvt>
|
|
||||||
#include <locale>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_POLL
|
#ifdef USE_POLL
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#endif
|
#endif
|
||||||
@ -416,15 +411,12 @@ void Sock::Close()
|
|||||||
m_socket = INVALID_SOCKET;
|
m_socket = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
std::string NetworkErrorString(int err)
|
std::string NetworkErrorString(int err)
|
||||||
{
|
{
|
||||||
|
#if defined(WIN32)
|
||||||
return Win32ErrorString(err);
|
return Win32ErrorString(err);
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
std::string NetworkErrorString(int err)
|
|
||||||
{
|
|
||||||
// On BSD sockets implementations, NetworkErrorString is the same as SysErrorString.
|
// On BSD sockets implementations, NetworkErrorString is the same as SysErrorString.
|
||||||
return SysErrorString(err);
|
return SysErrorString(err);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user