diff options
author | Guido van Rossum <guido@python.org> | 2003-02-19 17:50:16 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-02-19 17:50:16 (GMT) |
commit | b76bdf8ef7044145efb0bc74d513c867d29af4d1 (patch) | |
tree | 986f9e8a7ff44ebfeb912424163c87e1e8ddf06e /Modules/socketmodule.c | |
parent | 2ffec02b48e3cfb5209eb79eff80d0fb5ca8df38 (diff) | |
download | cpython-b76bdf8ef7044145efb0bc74d513c867d29af4d1.zip cpython-b76bdf8ef7044145efb0bc74d513c867d29af4d1.tar.gz cpython-b76bdf8ef7044145efb0bc74d513c867d29af4d1.tar.bz2 |
The connect timeout code wasn't working on Windows.
Rather than trying to second-guess the various error returns
of a second connect(), use select() to determine whether the
socket becomes writable (which means connected).
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 1b3321f..2b8e3ea 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1336,18 +1336,19 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen) if (s->sock_timeout > 0.0) { if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK) { - internal_select(s, 1); - res = connect(s->sock_fd, addr, addrlen); - if (res < 0) { - /* On Win98, WSAEISCONN was seen here. But - * on Win2K, WSAEINVAL. So accept both as - * meaning "fine". - */ - int code = WSAGetLastError(); - if (code == WSAEISCONN || - code == WSAEINVAL) - res = 0; - } + /* This is a mess. Best solution: trust select */ + fd_set fds; + struct timeval tv; + tv.tv_sec = (int)s->sock_timeout; + tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6); + FD_ZERO(&fds); + FD_SET(s->sock_fd, &fds); + res = select(s->sock_fd+1, NULL, &fds, NULL, &tv); + if (res == 0) + res = WSAEWOULDBLOCK; + else if (res > 0) + res = 0; + /* else if (res < 0) an error occurred */ } } |