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