[Python-checkins] python/dist/src/Modules socketmodule.c,1.256,1.257
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Wed, 19 Feb 2003 09:50:22 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv24517
Modified Files:
socketmodule.c
Log Message:
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).
Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.256
retrieving revision 1.257
diff -C2 -d -r1.256 -r1.257
*** socketmodule.c 13 Feb 2003 03:13:40 -0000 1.256
--- socketmodule.c 19 Feb 2003 17:50:16 -0000 1.257
***************
*** 1337,1352 ****
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;
! }
}
}
--- 1337,1353 ----
if (s->sock_timeout > 0.0) {
if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK) {
! /* 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 */
}
}