mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-26 22:03:24 +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
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
//! Mix-in for handling \c errno
|
||||
/*!
|
||||
This mix-in class for exception classes provides storage and query of
|
||||
\c errno.
|
||||
\c errno. On Windows, it uses GetLastError() instead of errno.
|
||||
*/
|
||||
class MXErrno {
|
||||
public:
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
MXErrno();
|
||||
//! Save \c err as the error code
|
||||
MXErrno(int err);
|
||||
virtual ~MXErrno();
|
||||
|
||||
//! @name accessors
|
||||
//@{
|
||||
@@ -71,12 +72,13 @@ public:
|
||||
int getErrno() const;
|
||||
|
||||
//! Get the human readable string for the error code
|
||||
const char* getErrstr() const;
|
||||
virtual const char* getErrstr() const;
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
int m_errno;
|
||||
mutable char* m_string;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user