summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-16 00:35:22 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-16 00:35:22 (GMT)
commit3d392eb3273aefeca2741aee9f0e31e3b79b1043 (patch)
tree7766b1aad797ebe0f8ee5316e561b3f37a45d3ea /Modules/socketmodule.c
parent5b8b1555de033c0f1646bce5fd130567297da019 (diff)
downloadcpython-3d392eb3273aefeca2741aee9f0e31e3b79b1043.zip
cpython-3d392eb3273aefeca2741aee9f0e31e3b79b1043.tar.gz
cpython-3d392eb3273aefeca2741aee9f0e31e3b79b1043.tar.bz2
Merged revisions 58947-59004 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r58952 | christian.heimes | 2007-11-12 10:58:08 -0800 (Mon, 12 Nov 2007) | 6 lines readline module cleanup fixed indention to tabs use Py_RETURN_NONE macro added more error checks to on_completion_display_matches_hook open question: Does PyList_SetItem(l, i, o) steal a reference to o in the case of an error? ........ r58956 | guido.van.rossum | 2007-11-12 12:06:40 -0800 (Mon, 12 Nov 2007) | 2 lines Add the test from issue 1704621 (the issue itself is already fixed here). ........ r58963 | amaury.forgeotdarc | 2007-11-13 13:54:28 -0800 (Tue, 13 Nov 2007) | 23 lines Merge from py3k branch: Correction for issue1265 (pdb bug with "with" statement). When an unfinished generator-iterator is garbage collected, PyEval_EvalFrameEx is called with a GeneratorExit exception set. This leads to funny results if the sys.settrace function itself makes use of generators. A visible effect is that the settrace function is reset to None. Another is that the eventual "finally" block of the generator is not called. It is necessary to save/restore the exception around the call to the trace function. This happens a lot with py3k: isinstance() of an ABCMeta instance runs def __instancecheck__(cls, instance): """Override for isinstance(instance, cls).""" return any(cls.__subclasscheck__(c) for c in {instance.__class__, type(instance)}) which lets an opened generator expression each time it returns True. Backport candidate, even if the case is less frequent in 2.5. ........ r58968 | georg.brandl | 2007-11-14 05:59:09 -0800 (Wed, 14 Nov 2007) | 2 lines Remove dead link from random docs. ........ r58971 | raymond.hettinger | 2007-11-14 14:56:16 -0800 (Wed, 14 Nov 2007) | 1 line Make __fields__ read-only. Suggested by Issac Morland ........ r58972 | raymond.hettinger | 2007-11-14 15:02:30 -0800 (Wed, 14 Nov 2007) | 1 line Add test for __fields__ being read-only ........ r58975 | raymond.hettinger | 2007-11-14 18:44:53 -0800 (Wed, 14 Nov 2007) | 6 lines Accept Issac Morland's suggestion for __replace__ to allow multiple replacements (suprisingly, this simplifies the signature, improves clarity, and is comparably fast). Update the docs to reflect a previous change to the function name. Add an example to the docs showing how to override the default __repr__ method. ........ r58976 | raymond.hettinger | 2007-11-14 18:55:42 -0800 (Wed, 14 Nov 2007) | 1 line Small improvement to the implementation of __replace__(). ........ r58977 | raymond.hettinger | 2007-11-14 18:58:20 -0800 (Wed, 14 Nov 2007) | 1 line Fixup example in docs. ........ r58978 | raymond.hettinger | 2007-11-14 19:16:09 -0800 (Wed, 14 Nov 2007) | 1 line Example of multiple replacements. ........ r58998 | raymond.hettinger | 2007-11-15 14:39:34 -0800 (Thu, 15 Nov 2007) | 1 line Add example for use cases requiring default values. ........ r59000 | bill.janssen | 2007-11-15 15:03:03 -0800 (Thu, 15 Nov 2007) | 1 line add the certificate for the Python SVN repository for testing SSL ........ r59004 | guido.van.rossum | 2007-11-15 16:24:44 -0800 (Thu, 15 Nov 2007) | 8 lines A patch from issue 1378 by roudkerk: Currently on Windows set_error() make use of a large array which maps socket error numbers to error messages. This patch removes that array and just lets PyErr_SetExcFromWindowsErr() generate the message by using the Win32 function FormatMessage(). ........
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c86
1 files changed, 5 insertions, 81 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 2621a9e..30e8d22 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -450,87 +450,11 @@ set_error(void)
{
#ifdef MS_WINDOWS
int err_no = WSAGetLastError();
- 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}
- };
- if (err_no) {
- PyObject *v;
- 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(socket_error, v);
- Py_DECREF(v);
- }
- return NULL;
- }
- else
+ /* PyErr_SetExcFromWindowsErr() invokes FormatMessage() which
+ recognizes the error codes used by both GetLastError() and
+ WSAGetLastError */
+ if (err_no)
+ return PyErr_SetExcFromWindowsErr(socket_error, err_no);
#endif
#if defined(PYOS_OS2) && !defined(PYCC_GCC)