mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-07 06:03:40 +08:00
added better network error message support.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
// win32 wants a const char* argument to std::exception c'tor
|
||||
#if WINDOWS_LIKE
|
||||
#include <windows.h>
|
||||
#define STDEXCEPTARG ""
|
||||
#endif
|
||||
|
||||
@@ -85,17 +86,32 @@ XBase::format(const char* /*id*/, const char* fmt, ...) const throw()
|
||||
//
|
||||
|
||||
MXErrno::MXErrno() :
|
||||
m_errno(errno)
|
||||
#if WINDOWS_LIKE
|
||||
m_errno(GetLastError()),
|
||||
#else
|
||||
m_errno(errno),
|
||||
#endif
|
||||
m_string(NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
MXErrno::MXErrno(int err) :
|
||||
m_errno(err)
|
||||
m_errno(err),
|
||||
m_string(NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
MXErrno::~MXErrno()
|
||||
{
|
||||
if (m_string != NULL) {
|
||||
#if WINDOWS_LIKE
|
||||
LocalFree(m_string);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
MXErrno::getErrno() const
|
||||
{
|
||||
@@ -105,5 +121,23 @@ MXErrno::getErrno() const
|
||||
const char*
|
||||
MXErrno::getErrstr() const
|
||||
{
|
||||
#if WINDOWS_LIKE
|
||||
if (m_string != NULL) {
|
||||
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
0,
|
||||
error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)&m_string,
|
||||
0,
|
||||
NULL) == 0) {
|
||||
m_string = NULL;
|
||||
return "unknown error";
|
||||
}
|
||||
}
|
||||
return m_string;
|
||||
#else
|
||||
return strerror(m_errno);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user