cpython: f841d3bc30ee (original) (raw)

--- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -601,6 +601,11 @@ internal_select_ex(PySocketSockObject *s { int n; +#ifdef WITH_THREAD

+#endif + /* Nothing to do unless we're in timeout mode (not non-blocking) */ if (s->sock_timeout <= 0.0) return 0; @@ -625,7 +630,10 @@ internal_select_ex(PySocketSockObject *s /* s->sock_timeout is in seconds, timeout in ms */ timeout = (int)(interval * 1000 + 0.5); +

#else { @@ -638,12 +646,14 @@ internal_select_ex(PySocketSockObject s FD_SET(s->sock_fd, &fds); / See if the socket is ready */

#endif @@ -667,11 +677,14 @@ internal_select(PySocketSockObject *s, i Here is an example of use: BEGIN_SELECT_LOOP(s)

+ timeout = internal_select_ex(s, 0, interval);

+

@@ -2066,9 +2079,10 @@ sock_accept(PySocketSockObject *s) BEGIN_SELECT_LOOP(s) do {

+ if (!timeout) {

#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if (accept4_works != 0) { newfd = accept4(s->sock_fd, SAS2SA(&addrbuf), &addrlen, @@ -2083,8 +2097,8 @@ sock_accept(PySocketSockObject *s) #else newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen); #endif

@@ -2395,51 +2409,59 @@ internal_connect(PySocketSockObject *s, { int res, timeout; + timeout = 0; +

+ #ifdef MS_WINDOWS

+

+

#else

+

+

if (timeout == 1) { PyErr_SetString(socket_timeout, "timed out"); @@ -2525,9 +2546,7 @@ sock_connect_ex(PySocketSockObject *s, P if (!getsockaddrarg(s, addro, SAS2SA(&addrbuf), &addrlen)) return NULL;

/* Signals are not errors (though they may raise exceptions). Adapted from PyErr_SetFromErrnoWithFilenameObject(). */ @@ -2679,9 +2698,10 @@ sock_recv_guts(PySocketSockObject *s, ch BEGIN_SELECT_LOOP(s) do {

+ if (!timeout) {

#ifdef MS_WINDOWS if (len > INT_MAX) len = INT_MAX; @@ -2689,8 +2709,8 @@ sock_recv_guts(PySocketSockObject *s, ch #else outlen = recv(s->sock_fd, cbuf, len, flags); #endif

+ if (!timeout) {

#ifdef MS_WINDOWS if (len > INT_MAX) len = INT_MAX; @@ -2866,8 +2887,8 @@ sock_recvfrom_guts(PySocketSockObject *s n = recvfrom(s->sock_fd, cbuf, len, flags, SAS2SA(&addrbuf), &addrlen); #endif

@@ -3062,13 +3082,17 @@ sock_recvmsg_guts(PySocketSockObject *s, msg.msg_control = controlbuf; msg.msg_controllen = controllen; timeout = internal_select_ex(s, 0, interval);

+ if (timeout == 1) { PyErr_SetString(socket_timeout, "timed out"); goto finally; } +

+ if (!timeout) {

#ifdef MS_WINDOWS if (len > INT_MAX) len = INT_MAX; @@ -3360,8 +3385,8 @@ sock_send(PySocketSockObject *s, PyObjec #else n = send(s->sock_fd, buf, len, flags); #endif

@@ -3406,10 +3431,11 @@ sock_sendall(PySocketSockObject *s, PyOb } do {

+ n = -1; if (!timeout) {

#ifdef MS_WINDOWS if (len > INT_MAX) len = INT_MAX; @@ -3417,8 +3443,8 @@ sock_sendall(PySocketSockObject *s, PyOb #else n = send(s->sock_fd, buf, len, flags); #endif

@@ -3495,9 +3521,10 @@ sock_sendto(PySocketSockObject *s, PyObj BEGIN_SELECT_LOOP(s) do {

+ if (!timeout) {

#ifdef MS_WINDOWS if (len > INT_MAX) len = INT_MAX; @@ -3507,8 +3534,8 @@ sock_sendto(PySocketSockObject *s, PyObj n = sendto(s->sock_fd, buf, len, flags, SAS2SA(&addrbuf), addrlen); #endif

+

+ if (timeout == 1) { PyErr_SetString(socket_timeout, "timed out"); goto finally;