|
@@ -67,46 +67,46 @@ bool NetworkError::IsConnectInProgress()
|
|
|
{
|
|
|
#if defined(_WIN32)
|
|
|
return this->error == WSAEWOULDBLOCK;
|
|
|
#else
|
|
|
return this->error == EINPROGRESS;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the string representation of the error message.
|
|
|
* @return The string representation that will get overwritten by next calls.
|
|
|
*/
|
|
|
const char *NetworkError::AsString() const
|
|
|
const std::string &NetworkError::AsString() const
|
|
|
{
|
|
|
if (this->message.empty()) {
|
|
|
#if defined(_WIN32)
|
|
|
char buffer[512];
|
|
|
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, this->error,
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL) == 0) {
|
|
|
seprintf(buffer, lastof(buffer), "Unknown error %d", this->error);
|
|
|
}
|
|
|
this->message.assign(buffer);
|
|
|
#else
|
|
|
/* Make strerror thread safe by locking access to it. There is a thread safe strerror_r, however
|
|
|
* the non-POSIX variant is available due to defining _GNU_SOURCE meaning it is not portable.
|
|
|
* The problem with the non-POSIX variant is that it does not necessarily fill the buffer with
|
|
|
* the error message but can also return a pointer to a static bit of memory, whereas the POSIX
|
|
|
* variant always fills the buffer. This makes the behaviour too erratic to work with. */
|
|
|
static std::mutex mutex;
|
|
|
std::lock_guard<std::mutex> guard(mutex);
|
|
|
this->message.assign(strerror(this->error));
|
|
|
#endif
|
|
|
}
|
|
|
return this->message.c_str();
|
|
|
return this->message;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Check whether an error was actually set.
|
|
|
* @return True iff an error was set.
|
|
|
*/
|
|
|
bool NetworkError::HasError() const
|
|
|
{
|
|
|
return this->error != 0;
|
|
|
}
|
|
|
|
|
|
/**
|