00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "XArchWindows.h"
00020 #include "CArchNetworkWinsock.h"
00021
00022
00023
00024
00025
00026 XArchEval*
00027 XArchEvalWindows::clone() const throw()
00028 {
00029 return new XArchEvalWindows(m_errno);
00030 }
00031
00032 std::string
00033 XArchEvalWindows::eval() const throw()
00034 {
00035 char* cmsg;
00036 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
00037 FORMAT_MESSAGE_IGNORE_INSERTS |
00038 FORMAT_MESSAGE_FROM_SYSTEM,
00039 0,
00040 m_errno,
00041 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00042 (LPTSTR)&cmsg,
00043 0,
00044 NULL) == 0) {
00045 cmsg = NULL;
00046 return "Unknown error";
00047 }
00048 std::string smsg(cmsg);
00049 LocalFree(cmsg);
00050 return smsg;
00051 }
00052
00053
00054
00055
00056
00057
00058 XArchEval*
00059 XArchEvalWinsock::clone() const throw()
00060 {
00061 return new XArchEvalWinsock(m_errno);
00062 }
00063
00064 std::string
00065 XArchEvalWinsock::eval() const throw()
00066 {
00067
00068
00069
00070 static const struct { int m_code; const char* m_msg; } s_netErrorCodes[] = {
00071 {WSAEINTR, "The (blocking) call was canceled via WSACancelBlockingCall"},
00072 {WSAEBADF, "Bad file handle"},
00073 {WSAEACCES, "The requested address is a broadcast address, but the appropriate flag was not set"},
00074 {WSAEFAULT, "WSAEFAULT"},
00075 {WSAEINVAL, "WSAEINVAL"},
00076 {WSAEMFILE, "No more file descriptors available"},
00077 {WSAEWOULDBLOCK, "Socket is marked as non-blocking and no connections are present or the receive operation would block"},
00078 {WSAEINPROGRESS, "A blocking Windows Sockets operation is in progress"},
00079 {WSAEALREADY, "The asynchronous routine being canceled has already completed"},
00080 {WSAENOTSOCK, "At least on descriptor is not a socket"},
00081 {WSAEDESTADDRREQ, "A destination address is required"},
00082 {WSAEMSGSIZE, "The datagram was too large to fit into the specified buffer and was truncated"},
00083 {WSAEPROTOTYPE, "The specified protocol is the wrong type for this socket"},
00084 {WSAENOPROTOOPT, "The option is unknown or unsupported"},
00085 {WSAEPROTONOSUPPORT,"The specified protocol is not supported"},
00086 {WSAESOCKTNOSUPPORT,"The specified socket type is not supported by this address family"},
00087 {WSAEOPNOTSUPP, "The referenced socket is not a type that supports that operation"},
00088 {WSAEPFNOSUPPORT, "BSD: Protocol family not supported"},
00089 {WSAEAFNOSUPPORT, "The specified address family is not supported"},
00090 {WSAEADDRINUSE, "The specified address is already in use"},
00091 {WSAEADDRNOTAVAIL, "The specified address is not available from the local machine"},
00092 {WSAENETDOWN, "The Windows Sockets implementation has detected that the network subsystem has failed"},
00093 {WSAENETUNREACH, "The network can't be reached from this host at this time"},
00094 {WSAENETRESET, "The connection must be reset because the Windows Sockets implementation dropped it"},
00095 {WSAECONNABORTED, "The virtual circuit was aborted due to timeout or other failure"},
00096 {WSAECONNRESET, "The virtual circuit was reset by the remote side"},
00097 {WSAENOBUFS, "No buffer space is available or a buffer deadlock has occured. The socket cannot be created"},
00098 {WSAEISCONN, "The socket is already connected"},
00099 {WSAENOTCONN, "The socket is not connected"},
00100 {WSAESHUTDOWN, "The socket has been shutdown"},
00101 {WSAETOOMANYREFS, "BSD: Too many references"},
00102 {WSAETIMEDOUT, "Attempt to connect timed out without establishing a connection"},
00103 {WSAECONNREFUSED, "Connection was refused"},
00104 {WSAELOOP, "Undocumented WinSock error code used in BSD"},
00105 {WSAENAMETOOLONG, "Undocumented WinSock error code used in BSD"},
00106 {WSAEHOSTDOWN, "Undocumented WinSock error code used in BSD"},
00107 {WSAEHOSTUNREACH, "No route to host"},
00108 {WSAENOTEMPTY, "Undocumented WinSock error code"},
00109 {WSAEPROCLIM, "Undocumented WinSock error code"},
00110 {WSAEUSERS, "Undocumented WinSock error code"},
00111 {WSAEDQUOT, "Undocumented WinSock error code"},
00112 {WSAESTALE, "Undocumented WinSock error code"},
00113 {WSAEREMOTE, "Undocumented WinSock error code"},
00114 {WSASYSNOTREADY, "Underlying network subsytem is not ready for network communication"},
00115 {WSAVERNOTSUPPORTED, "The version of WinSock API support requested is not provided in this implementation"},
00116 {WSANOTINITIALISED, "WinSock subsystem not properly initialized"},
00117 {WSAEDISCON, "Virtual circuit has gracefully terminated connection"},
00118 {WSAHOST_NOT_FOUND, "The specified host is unknown"},
00119 {WSATRY_AGAIN, "A temporary error occurred on an authoritative name server"},
00120 {WSANO_RECOVERY, "A non-recoverable name server error occurred"},
00121 {WSANO_DATA, "The requested name is valid but does not have an IP address"},
00122 {0, NULL}
00123 };
00124
00125 for (unsigned int i = 0; s_netErrorCodes[i].m_code != 0; ++i) {
00126 if (s_netErrorCodes[i].m_code == m_errno) {
00127 return s_netErrorCodes[i].m_msg;
00128 }
00129 }
00130 return "Unknown error";
00131 }