summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMark Hammond <mhammond@skippinet.com.au>2000-07-24 01:45:11 (GMT)
committerMark Hammond <mhammond@skippinet.com.au>2000-07-24 01:45:11 (GMT)
commit46a733dfbfabfc76c0732d02db796f4d39e400aa (patch)
treea7a2b1477c0f1871f46e94416d7d65a6dc3c2652 /Modules
parente28c296f0febd56ff082ed07f542e1e6c3b8a2bd (diff)
downloadcpython-46a733dfbfabfc76c0732d02db796f4d39e400aa.zip
cpython-46a733dfbfabfc76c0732d02db796f4d39e400aa.tar.gz
cpython-46a733dfbfabfc76c0732d02db796f4d39e400aa.tar.bz2
Patch #100926 - Better error messages for socket exceptions on Windows. [Slight style differences from posted patch]
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c80
1 files changed, 78 insertions, 2 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 5d6f24a..914931f 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -231,9 +231,85 @@ static PyObject *
PySocket_Err(void)
{
#ifdef MS_WINDOWS
- if (WSAGetLastError()) {
+ int err_no = WSAGetLastError();
+ if (err_no) {
+ static struct { int no; const char *msg; } *msgp, msgs[] = {
+ { WSAEINTR, "Interrupted system call" },
+ { WSAEBADF, "Bad file descriptor" },
+ { WSAEACCES, "Permission denied" },
+ { WSAEFAULT, "Bad address" },
+ { WSAEINVAL, "Invalid argument" },
+ { WSAEMFILE, "Too many open files" },
+ { WSAEWOULDBLOCK,
+ "The socket operation could not complete "
+ "without blocking" },
+ { WSAEINPROGRESS, "Operation now in progress" },
+ { WSAEALREADY, "Operation already in progress" },
+ { WSAENOTSOCK, "Socket operation on non-socket" },
+ { WSAEDESTADDRREQ, "Destination address required" },
+ { WSAEMSGSIZE, "Message too long" },
+ { WSAEPROTOTYPE, "Protocol wrong type for socket" },
+ { WSAENOPROTOOPT, "Protocol not available" },
+ { WSAEPROTONOSUPPORT, "Protocol not supported" },
+ { WSAESOCKTNOSUPPORT, "Socket type not supported" },
+ { WSAEOPNOTSUPP, "Operation not supported" },
+ { WSAEPFNOSUPPORT, "Protocol family not supported" },
+ { WSAEAFNOSUPPORT, "Address family not supported" },
+ { WSAEADDRINUSE, "Address already in use" },
+ { WSAEADDRNOTAVAIL,
+ "Can't assign requested address" },
+ { WSAENETDOWN, "Network is down" },
+ { WSAENETUNREACH, "Network is unreachable" },
+ { WSAENETRESET,
+ "Network dropped connection on reset" },
+ { WSAECONNABORTED,
+ "Software caused connection abort" },
+ { WSAECONNRESET, "Connection reset by peer" },
+ { WSAENOBUFS, "No buffer space available" },
+ { WSAEISCONN, "Socket is already connected" },
+ { WSAENOTCONN, "Socket is not connected" },
+ { WSAESHUTDOWN, "Can't send after socket shutdown" },
+ { WSAETOOMANYREFS,
+ "Too many references: can't splice" },
+ { WSAETIMEDOUT, "Operation timed out" },
+ { WSAECONNREFUSED, "Connection refused" },
+ { WSAELOOP, "Too many levels of symbolic links" },
+ { WSAENAMETOOLONG, "File name too long" },
+ { WSAEHOSTDOWN, "Host is down" },
+ { WSAEHOSTUNREACH, "No route to host" },
+ { WSAENOTEMPTY, "Directory not empty" },
+ { WSAEPROCLIM, "Too many processes" },
+ { WSAEUSERS, "Too many users" },
+ { WSAEDQUOT, "Disc quota exceeded" },
+ { WSAESTALE, "Stale NFS file handle" },
+ { WSAEREMOTE, "Too many levels of remote in path" },
+ { WSASYSNOTREADY,
+ "Network subsystem is unvailable" },
+ { WSAVERNOTSUPPORTED,
+ "WinSock version is not supported" },
+ { WSANOTINITIALISED,
+ "Successful WSAStartup() not yet performed" },
+ { WSAEDISCON, "Graceful shutdown in progress" },
+ /* Resolver errors */
+ { WSAHOST_NOT_FOUND, "No such host is known" },
+ { WSATRY_AGAIN, "Host not found, or server failed" },
+ { WSANO_RECOVERY,
+ "Unexpected server error encountered" },
+ { WSANO_DATA, "Valid name without requested data" },
+ { WSANO_ADDRESS, "No address, look for MX record" },
+ { 0, NULL }
+ };
PyObject *v;
- v = Py_BuildValue("(is)", WSAGetLastError(), "winsock error");
+ const char *msg = "winsock error";
+
+ for (msgp = msgs; msgp->msg; msgp++) {
+ if (err_no == msgp->no) {
+ msg = msgp->msg;
+ break;
+ }
+ }
+
+ v = Py_BuildValue("(is)", err_no, msg);
if (v != NULL) {
PyErr_SetObject(PySocket_Error, v);
Py_DECREF(v);