Index: Modules/socketmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v retrieving revision 1.311 diff -u -r1.311 socketmodule.c --- Modules/socketmodule.c 7 Nov 2004 14:24:25 -0000 1.311 +++ Modules/socketmodule.c 15 Jan 2005 11:16:31 -0000 @@ -627,7 +627,8 @@ The argument writing indicates the direction. This does not raise an exception; we'll let our caller do that after they've reacquired the interpreter lock. - Returns 1 on timeout, 0 otherwise. */ + Returns 1 on timeout, 0 otherwise. + Returns -1 when an error condition occurred. */ static int internal_select(PySocketSockObject *s, int writing) { @@ -656,7 +657,10 @@ n = select(s->sock_fd+1, &fds, NULL, NULL, &tv); if (n == 0) return 1; - return 0; + else if (n == -1) + return -1; /* an error occurred */ + else + return 0; } /* Initialize a new socket object. */ @@ -1369,6 +1373,9 @@ &addrlen); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + return PyErr_SetFromErrno(socket_error); + } if (timeout) { PyErr_SetString(socket_timeout, "timed out"); return NULL; @@ -1737,6 +1744,7 @@ if (s->sock_timeout > 0.0) { if (res < 0 && errno == EINPROGRESS) { timeout = internal_select(s, 1); + // XXX not sure if/how we should test errno here... res = connect(s->sock_fd, addr, addrlen); if (res < 0 && errno == EISCONN) res = 0; @@ -2045,6 +2053,10 @@ n = recv(s->sock_fd, PyString_AS_STRING(buf), len, flags); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + Py_DECREF(buf); + return PyErr_SetFromErrno(socket_error); + } if (timeout) { Py_DECREF(buf); PyErr_SetString(socket_timeout, "timed out"); @@ -2076,6 +2088,10 @@ n = recv(s->sock_fd, read_buf, segment, flags); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + Py_DECREF(buf); + return PyErr_SetFromErrno(socket_error); + } if (timeout) { Py_DECREF(buf); PyErr_SetString(socket_timeout, "timed out"); @@ -2148,6 +2164,10 @@ ); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + Py_DECREF(buf); + return PyErr_SetFromErrno(socket_error); + } if (timeout) { Py_DECREF(buf); PyErr_SetString(socket_timeout, "timed out"); @@ -2199,6 +2219,9 @@ n = send(s->sock_fd, buf, len, flags); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + return PyErr_SetFromErrno(socket_error); + } if (timeout) { PyErr_SetString(socket_timeout, "timed out"); return NULL; @@ -2224,6 +2247,9 @@ if (!timeout) n = send(s->sock_fd, buf, segment, flags); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + return PyErr_SetFromErrno(socket_error); + } if (timeout) { PyErr_SetString(socket_timeout, "timed out"); return NULL; @@ -2270,6 +2296,9 @@ } while (len > 0); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + return PyErr_SetFromErrno(socket_error); + } if (timeout) { PyErr_SetString(socket_timeout, "timed out"); return NULL; @@ -2317,6 +2346,9 @@ n = sendto(s->sock_fd, buf, len, flags, addr, addrlen); Py_END_ALLOW_THREADS + if (timeout==-1 && errno) { + return PyErr_SetFromErrno(socket_error); + } if (timeout) { PyErr_SetString(socket_timeout, "timed out"); return NULL;