added better network error message support.

This commit is contained in:
crs
2002-09-14 20:56:28 +00:00
parent 4586f88188
commit fec679cfe5
8 changed files with 155 additions and 54 deletions

View File

@@ -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
}