XArchWindows.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "XArchWindows.h"
00016 #include "CArchNetworkWinsock.h"
00017 
00018 //
00019 // XArchEvalWindows
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 // XArchEvalWinsock
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     // built-in windows function for looking up error message strings
00064     // may not look up network error messages correctly.  we'll have
00065     // to do it ourself.
00066     static const struct { int m_code; const char* m_msg; } s_netErrorCodes[] = {
00067         /* 10004 */{WSAEINTR,           "The (blocking) call was canceled via WSACancelBlockingCall"},
00068         /* 10009 */{WSAEBADF,           "Bad file handle"},
00069         /* 10013 */{WSAEACCES,          "The requested address is a broadcast address, but the appropriate flag was not set"},
00070         /* 10014 */{WSAEFAULT,          "WSAEFAULT"},
00071         /* 10022 */{WSAEINVAL,          "WSAEINVAL"},
00072         /* 10024 */{WSAEMFILE,          "No more file descriptors available"},
00073         /* 10035 */{WSAEWOULDBLOCK,     "Socket is marked as non-blocking and no connections are present or the receive operation would block"},
00074         /* 10036 */{WSAEINPROGRESS,     "A blocking Windows Sockets operation is in progress"},
00075         /* 10037 */{WSAEALREADY,        "The asynchronous routine being canceled has already completed"},
00076         /* 10038 */{WSAENOTSOCK,        "At least on descriptor is not a socket"},
00077         /* 10039 */{WSAEDESTADDRREQ,    "A destination address is required"},
00078         /* 10040 */{WSAEMSGSIZE,        "The datagram was too large to fit into the specified buffer and was truncated"},
00079         /* 10041 */{WSAEPROTOTYPE,      "The specified protocol is the wrong type for this socket"},
00080         /* 10042 */{WSAENOPROTOOPT,     "The option is unknown or unsupported"},
00081         /* 10043 */{WSAEPROTONOSUPPORT,"The specified protocol is not supported"},
00082         /* 10044 */{WSAESOCKTNOSUPPORT,"The specified socket type is not supported by this address family"},
00083         /* 10045 */{WSAEOPNOTSUPP,      "The referenced socket is not a type that supports that operation"},
00084         /* 10046 */{WSAEPFNOSUPPORT,    "BSD: Protocol family not supported"},
00085         /* 10047 */{WSAEAFNOSUPPORT,    "The specified address family is not supported"},
00086         /* 10048 */{WSAEADDRINUSE,      "The specified address is already in use"},
00087         /* 10049 */{WSAEADDRNOTAVAIL,   "The specified address is not available from the local machine"},
00088         /* 10050 */{WSAENETDOWN,        "The Windows Sockets implementation has detected that the network subsystem has failed"},
00089         /* 10051 */{WSAENETUNREACH,     "The network can't be reached from this hos at this time"},
00090         /* 10052 */{WSAENETRESET,       "The connection must be reset because the Windows Sockets implementation dropped it"},
00091         /* 10053 */{WSAECONNABORTED,    "The virtual circuit was aborted due to timeout or other failure"},
00092         /* 10054 */{WSAECONNRESET,      "The virtual circuit was reset by the remote side"},
00093         /* 10055 */{WSAENOBUFS,         "No buffer space is available or a buffer deadlock has occured. The socket cannot be created"},
00094         /* 10056 */{WSAEISCONN,         "The socket is already connected"},
00095         /* 10057 */{WSAENOTCONN,        "The socket is not connected"},
00096         /* 10058 */{WSAESHUTDOWN,       "The socket has been shutdown"},
00097         /* 10059 */{WSAETOOMANYREFS,    "BSD: Too many references"},
00098         /* 10060 */{WSAETIMEDOUT,       "Attempt to connect timed out without establishing a connection"},
00099         /* 10061 */{WSAECONNREFUSED,    "The attempt to connect was forcefully rejected"},
00100         /* 10062 */{WSAELOOP,           "Undocumented WinSock error code used in BSD"},
00101         /* 10063 */{WSAENAMETOOLONG,    "Undocumented WinSock error code used in BSD"},
00102         /* 10064 */{WSAEHOSTDOWN,       "Undocumented WinSock error code used in BSD"},
00103         /* 10065 */{WSAEHOSTUNREACH,    "No route to host"},
00104         /* 10066 */{WSAENOTEMPTY,       "Undocumented WinSock error code"},
00105         /* 10067 */{WSAEPROCLIM,        "Undocumented WinSock error code"},
00106         /* 10068 */{WSAEUSERS,          "Undocumented WinSock error code"},
00107         /* 10069 */{WSAEDQUOT,          "Undocumented WinSock error code"},
00108         /* 10070 */{WSAESTALE,          "Undocumented WinSock error code"},
00109         /* 10071 */{WSAEREMOTE,         "Undocumented WinSock error code"},
00110         /* 10091 */{WSASYSNOTREADY,     "Underlying network subsytem is not ready for network communication"},
00111         /* 10092 */{WSAVERNOTSUPPORTED, "The version of WinSock API support requested is not provided in this implementation"},
00112         /* 10093 */{WSANOTINITIALISED,  "WinSock subsystem not properly initialized"},
00113         /* 10101 */{WSAEDISCON,         "Virtual circuit has gracefully terminated connection"},
00114         /* 11001 */{WSAHOST_NOT_FOUND,  "The specified host is unknown"},
00115         /* 11002 */{WSATRY_AGAIN,       "A temporary error occurred on an authoritative name server"},
00116         /* 11003 */{WSANO_RECOVERY,     "A non-recoverable name server error occurred"},
00117         /* 11004 */{WSANO_DATA,         "The requested name is valid but does not have an IP address"},
00118         /* end   */{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 }

Generated on Fri Nov 6 00:18:46 2009 for synergy-plus by  doxygen 1.4.7