refactor: use windowsErrorToString instead of obsolete winsockErrorToString
This commit is contained in:
parent
fe179556ad
commit
3a242e7fc1
3 changed files with 22 additions and 209 deletions
|
|
@ -135,7 +135,7 @@ void ArchNetworkWinsock::initModule(HMODULE module)
|
||||||
WSADATA data;
|
WSADATA data;
|
||||||
int err = startup(version, &data);
|
int err = startup(version, &data);
|
||||||
if (data.wVersion != version) {
|
if (data.wVersion != version) {
|
||||||
throw ArchNetworkSupportException(winsockErrorToString(err));
|
throw ArchNetworkSupportException(windowsErrorToString(err));
|
||||||
}
|
}
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
// some other initialization error
|
// some other initialization error
|
||||||
|
|
@ -819,12 +819,12 @@ bool ArchNetworkWinsock::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case WSAEACCES:
|
case WSAEACCES:
|
||||||
throw ArchNetworkAccessException(winsockErrorToString(err));
|
throw ArchNetworkAccessException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAEMFILE:
|
case WSAEMFILE:
|
||||||
case WSAENOBUFS:
|
case WSAENOBUFS:
|
||||||
case WSAENETDOWN:
|
case WSAENETDOWN:
|
||||||
throw ArchNetworkResourceException(winsockErrorToString(err));
|
throw ArchNetworkResourceException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAEPROTOTYPE:
|
case WSAEPROTOTYPE:
|
||||||
case WSAEPROTONOSUPPORT:
|
case WSAEPROTONOSUPPORT:
|
||||||
|
|
@ -838,50 +838,50 @@ bool ArchNetworkWinsock::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
|
||||||
case WSANOTINITIALISED:
|
case WSANOTINITIALISED:
|
||||||
case WSAVERNOTSUPPORTED:
|
case WSAVERNOTSUPPORTED:
|
||||||
case WSASYSNOTREADY:
|
case WSASYSNOTREADY:
|
||||||
throw ArchNetworkSupportException(winsockErrorToString(err));
|
throw ArchNetworkSupportException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAEADDRNOTAVAIL:
|
case WSAEADDRNOTAVAIL:
|
||||||
throw ArchNetworkNoAddressException(winsockErrorToString(err));
|
throw ArchNetworkNoAddressException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAEADDRINUSE:
|
case WSAEADDRINUSE:
|
||||||
throw ArchNetworkAddressInUseException(winsockErrorToString(err));
|
throw ArchNetworkAddressInUseException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAEHOSTUNREACH:
|
case WSAEHOSTUNREACH:
|
||||||
case WSAENETUNREACH:
|
case WSAENETUNREACH:
|
||||||
throw ArchNetworkNoRouteException(winsockErrorToString(err));
|
throw ArchNetworkNoRouteException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAENOTCONN:
|
case WSAENOTCONN:
|
||||||
throw ArchNetworkNotConnectedException(winsockErrorToString(err));
|
throw ArchNetworkNotConnectedException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAEDISCON:
|
case WSAEDISCON:
|
||||||
throw ArchNetworkShutdownException(winsockErrorToString(err));
|
throw ArchNetworkShutdownException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAENETRESET:
|
case WSAENETRESET:
|
||||||
case WSAECONNABORTED:
|
case WSAECONNABORTED:
|
||||||
case WSAECONNRESET:
|
case WSAECONNRESET:
|
||||||
throw ArchNetworkDisconnectedException(winsockErrorToString(err));
|
throw ArchNetworkDisconnectedException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAECONNREFUSED:
|
case WSAECONNREFUSED:
|
||||||
throw ArchNetworkConnectionRefusedException(winsockErrorToString(err));
|
throw ArchNetworkConnectionRefusedException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAEHOSTDOWN:
|
case WSAEHOSTDOWN:
|
||||||
case WSAETIMEDOUT:
|
case WSAETIMEDOUT:
|
||||||
throw ArchNetworkTimedOutException(winsockErrorToString(err));
|
throw ArchNetworkTimedOutException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSAHOST_NOT_FOUND:
|
case WSAHOST_NOT_FOUND:
|
||||||
throw ArchNetworkNameUnknownException(winsockErrorToString(err));
|
throw ArchNetworkNameUnknownException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSANO_DATA:
|
case WSANO_DATA:
|
||||||
throw ArchNetworkNameNoAddressException(winsockErrorToString(err));
|
throw ArchNetworkNameNoAddressException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSANO_RECOVERY:
|
case WSANO_RECOVERY:
|
||||||
throw ArchNetworkNameFailureException(winsockErrorToString(err));
|
throw ArchNetworkNameFailureException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSATRY_AGAIN:
|
case WSATRY_AGAIN:
|
||||||
throw ArchNetworkNameUnavailableException(winsockErrorToString(err));
|
throw ArchNetworkNameUnavailableException(windowsErrorToString(err));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw ArchNetworkException(winsockErrorToString(err));
|
throw ArchNetworkException(windowsErrorToString(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -889,18 +889,18 @@ bool ArchNetworkWinsock::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case WSAHOST_NOT_FOUND:
|
case WSAHOST_NOT_FOUND:
|
||||||
throw ArchNetworkNameUnknownException(winsockErrorToString(err));
|
throw ArchNetworkNameUnknownException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSANO_DATA:
|
case WSANO_DATA:
|
||||||
throw ArchNetworkNameNoAddressException(winsockErrorToString(err));
|
throw ArchNetworkNameNoAddressException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSANO_RECOVERY:
|
case WSANO_RECOVERY:
|
||||||
throw ArchNetworkNameFailureException(winsockErrorToString(err));
|
throw ArchNetworkNameFailureException(windowsErrorToString(err));
|
||||||
|
|
||||||
case WSATRY_AGAIN:
|
case WSATRY_AGAIN:
|
||||||
throw ArchNetworkNameUnavailableException(winsockErrorToString(err));
|
throw ArchNetworkNameUnavailableException(windowsErrorToString(err));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw ArchNetworkNameException(winsockErrorToString(err));
|
throw ArchNetworkNameException(windowsErrorToString(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,192 +30,7 @@ QString windowsErrorToQString(DWORD error)
|
||||||
return QString("[%1] %2").arg(error).arg(message.trimmed());
|
return QString("[%1] %2").arg(error).arg(message.trimmed());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString winsockErrorToQString(int error)
|
|
||||||
{
|
|
||||||
// built-in windows function for looking up error message strings
|
|
||||||
// may not look up network error messages correctly. we'll have
|
|
||||||
// to do it ourself.
|
|
||||||
static const struct
|
|
||||||
{
|
|
||||||
int m_code;
|
|
||||||
const char *m_msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_netErrorCodes[] = {
|
|
||||||
|
|
||||||
// 10004
|
|
||||||
{WSAEINTR, "The (blocking) call was canceled via WSACancelBlockingCall"},
|
|
||||||
|
|
||||||
// 10009
|
|
||||||
{WSAEBADF, "Bad file handle"},
|
|
||||||
|
|
||||||
// 10013
|
|
||||||
{WSAEACCES, "The requested address is a broadcast address, but the appropriate flag was not set"},
|
|
||||||
|
|
||||||
// 10014
|
|
||||||
{WSAEFAULT, "WSAEFAULT"},
|
|
||||||
|
|
||||||
// 10022
|
|
||||||
{WSAEINVAL, "WSAEINVAL"},
|
|
||||||
|
|
||||||
// 10024
|
|
||||||
{WSAEMFILE, "No more file descriptors available"},
|
|
||||||
|
|
||||||
// 10035
|
|
||||||
{WSAEWOULDBLOCK,
|
|
||||||
"Socket is marked as non-blocking and no connections are present or the receive operation would block"},
|
|
||||||
|
|
||||||
// 10036
|
|
||||||
{WSAEINPROGRESS, "A blocking Windows Sockets operation is in progress"},
|
|
||||||
|
|
||||||
// 10037
|
|
||||||
{WSAEALREADY, "The asynchronous routine being canceled has already completed"},
|
|
||||||
|
|
||||||
// 10038
|
|
||||||
{WSAENOTSOCK, "At least on descriptor is not a socket"},
|
|
||||||
|
|
||||||
// 10039
|
|
||||||
{WSAEDESTADDRREQ, "A destination address is required"},
|
|
||||||
|
|
||||||
// 10040
|
|
||||||
{WSAEMSGSIZE, "The datagram was too large to fit into the specified buffer and was truncated"},
|
|
||||||
|
|
||||||
// 10041
|
|
||||||
{WSAEPROTOTYPE, "The specified protocol is the wrong type for this socket"},
|
|
||||||
|
|
||||||
// 10042
|
|
||||||
{WSAENOPROTOOPT, "The option is unknown or unsupported"},
|
|
||||||
|
|
||||||
// 10043
|
|
||||||
{WSAEPROTONOSUPPORT, "The specified protocol is not supported"},
|
|
||||||
|
|
||||||
// 10044
|
|
||||||
{WSAESOCKTNOSUPPORT, "The specified socket type is not supported by this address family"},
|
|
||||||
|
|
||||||
// 10045
|
|
||||||
{WSAEOPNOTSUPP, "The referenced socket is not a type that supports that operation"},
|
|
||||||
|
|
||||||
// 10046
|
|
||||||
{WSAEPFNOSUPPORT, "BSD: Protocol family not supported"},
|
|
||||||
|
|
||||||
// 10047
|
|
||||||
{WSAEAFNOSUPPORT, "The specified address family is not supported"},
|
|
||||||
|
|
||||||
// 10048
|
|
||||||
{WSAEADDRINUSE, "The specified address is already in use"},
|
|
||||||
|
|
||||||
// 10049
|
|
||||||
{WSAEADDRNOTAVAIL, "The specified address is not available from the local machine"},
|
|
||||||
|
|
||||||
// 10050
|
|
||||||
{WSAENETDOWN, "The Windows Sockets implementation has detected that the network subsystem has failed"},
|
|
||||||
|
|
||||||
// 10051
|
|
||||||
{WSAENETUNREACH, "The network can't be reached from this host at this time"},
|
|
||||||
|
|
||||||
// 10052
|
|
||||||
{WSAENETRESET, "The connection must be reset because the Windows Sockets implementation dropped it"},
|
|
||||||
|
|
||||||
// 10053
|
|
||||||
{WSAECONNABORTED, "The virtual circuit was aborted due to timeout or other failure"},
|
|
||||||
|
|
||||||
// 10054
|
|
||||||
{WSAECONNRESET, "The virtual circuit was reset by the remote side"},
|
|
||||||
|
|
||||||
// 10055
|
|
||||||
{WSAENOBUFS, "No buffer space is available or a buffer deadlock has occurred. The socket cannot be created"},
|
|
||||||
|
|
||||||
// 10056
|
|
||||||
{WSAEISCONN, "The socket is already connected"},
|
|
||||||
|
|
||||||
// 10057
|
|
||||||
{WSAENOTCONN, "The socket is not connected"},
|
|
||||||
|
|
||||||
// 10058
|
|
||||||
{WSAESHUTDOWN, "The socket has been shutdown"},
|
|
||||||
|
|
||||||
// 10059
|
|
||||||
{WSAETOOMANYREFS, "BSD: Too many references"},
|
|
||||||
|
|
||||||
// 10060
|
|
||||||
{WSAETIMEDOUT, "Attempt to connect timed out without establishing a connection"},
|
|
||||||
|
|
||||||
// 10061
|
|
||||||
{WSAECONNREFUSED, "Connection was refused"},
|
|
||||||
|
|
||||||
// 10062
|
|
||||||
{WSAELOOP, "Undocumented WinSock error code used in BSD"},
|
|
||||||
|
|
||||||
// 10063
|
|
||||||
{WSAENAMETOOLONG, "Undocumented WinSock error code used in BSD"},
|
|
||||||
|
|
||||||
// 10064
|
|
||||||
{WSAEHOSTDOWN, "Undocumented WinSock error code used in BSD"},
|
|
||||||
|
|
||||||
// 10065
|
|
||||||
{WSAEHOSTUNREACH, "No route to host"},
|
|
||||||
|
|
||||||
// 10066
|
|
||||||
{WSAENOTEMPTY, "Undocumented WinSock error code"},
|
|
||||||
|
|
||||||
// 10067
|
|
||||||
{WSAEPROCLIM, "Undocumented WinSock error code"},
|
|
||||||
|
|
||||||
// 10068
|
|
||||||
{WSAEUSERS, "Undocumented WinSock error code"},
|
|
||||||
|
|
||||||
// 10069
|
|
||||||
{WSAEDQUOT, "Undocumented WinSock error code"},
|
|
||||||
|
|
||||||
// 10070
|
|
||||||
{WSAESTALE, "Undocumented WinSock error code"},
|
|
||||||
|
|
||||||
// 10071
|
|
||||||
{WSAEREMOTE, "Undocumented WinSock error code"},
|
|
||||||
|
|
||||||
// 10091
|
|
||||||
{WSASYSNOTREADY, "Underlying network subsytem is not ready for network communication"},
|
|
||||||
|
|
||||||
// 10092
|
|
||||||
{WSAVERNOTSUPPORTED, "The version of WinSock API support requested is not provided in this implementation"},
|
|
||||||
|
|
||||||
// 10093
|
|
||||||
{WSANOTINITIALISED, "WinSock subsystem not properly initialized"},
|
|
||||||
|
|
||||||
// 10101
|
|
||||||
{WSAEDISCON, "Virtual circuit has gracefully terminated connection"},
|
|
||||||
|
|
||||||
// 11001
|
|
||||||
{WSAHOST_NOT_FOUND, "The specified host is unknown"},
|
|
||||||
|
|
||||||
// 11002
|
|
||||||
{WSATRY_AGAIN, "A temporary error occurred on an authoritative name server"},
|
|
||||||
|
|
||||||
// 11003
|
|
||||||
{WSANO_RECOVERY, "A non-recoverable name server error occurred"},
|
|
||||||
|
|
||||||
// 11004
|
|
||||||
{WSANO_DATA, "The requested name is valid but does not have an IP address"},
|
|
||||||
|
|
||||||
// end
|
|
||||||
{0, nullptr}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (unsigned int i = 0; s_netErrorCodes[i].m_code != 0; ++i) {
|
|
||||||
if (s_netErrorCodes[i].m_code == error) {
|
|
||||||
return QString("[%1] %2").arg(error).arg(s_netErrorCodes[i].m_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString("Unknown Winsock error: %1").arg(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string windowsErrorToString(DWORD error)
|
std::string windowsErrorToString(DWORD error)
|
||||||
{
|
{
|
||||||
return windowsErrorToQString(error).toStdString();
|
return windowsErrorToQString(error).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string winsockErrorToString(int error)
|
|
||||||
{
|
|
||||||
return winsockErrorToQString(error).toStdString();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,5 @@
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
QString winsockErrorToQString(int error);
|
|
||||||
QString windowsErrorToQString(DWORD error);
|
QString windowsErrorToQString(DWORD error);
|
||||||
std::string winsockErrorToString(int error);
|
|
||||||
std::string windowsErrorToString(DWORD error);
|
std::string windowsErrorToString(DWORD error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue