Kaydet (Commit) b76bdf8e authored tarafından Guido van Rossum's avatar Guido van Rossum

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).
üst 2ffec02b
...@@ -1336,18 +1336,19 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen) ...@@ -1336,18 +1336,19 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen)
if (s->sock_timeout > 0.0) { if (s->sock_timeout > 0.0) {
if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK) { if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK) {
internal_select(s, 1); /* This is a mess. Best solution: trust select */
res = connect(s->sock_fd, addr, addrlen); fd_set fds;
if (res < 0) { struct timeval tv;
/* On Win98, WSAEISCONN was seen here. But tv.tv_sec = (int)s->sock_timeout;
* on Win2K, WSAEINVAL. So accept both as tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
* meaning "fine". FD_ZERO(&fds);
*/ FD_SET(s->sock_fd, &fds);
int code = WSAGetLastError(); res = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
if (code == WSAEISCONN || if (res == 0)
code == WSAEINVAL) res = WSAEWOULDBLOCK;
res = 0; else if (res > 0)
} res = 0;
/* else if (res < 0) an error occurred */
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment