[Python-checkins] python/dist/src/Modules socketmodule.c, 1.296, 1.297

mhammond at users.sourceforge.net mhammond at users.sourceforge.net
Tue Aug 3 07:06:28 CEST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12067

Modified Files:
	socketmodule.c 
Log Message:
Fix [ 1001018 ]: Windows: setdefaulttimeout causes unnecessary timeouts on 
connect error


Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.296
retrieving revision 1.297
diff -C2 -d -r1.296 -r1.297
*** socketmodule.c	19 Jul 2004 17:01:20 -0000	1.296
--- socketmodule.c	3 Aug 2004 05:06:26 -0000	1.297
***************
*** 1695,1698 ****
--- 1695,1699 ----
  			/* This is a mess.  Best solution: trust select */
  			fd_set fds;
+ 			fd_set fds_exc;
  			struct timeval tv;
  			tv.tv_sec = (int)s->sock_timeout;
***************
*** 1700,1709 ****
  			FD_ZERO(&fds);
  			FD_SET(s->sock_fd, &fds);
! 			res = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
  			if (res == 0) {
  				res = WSAEWOULDBLOCK;
  				timeout = 1;
! 			} else if (res > 0)
! 				res = 0;
  			/* else if (res < 0) an error occurred */
  		}
--- 1701,1730 ----
  			FD_ZERO(&fds);
  			FD_SET(s->sock_fd, &fds);
! 			FD_ZERO(&fds_exc);
! 			FD_SET(s->sock_fd, &fds_exc);
! 			res = select(s->sock_fd+1, NULL, &fds, &fds_exc, &tv);
  			if (res == 0) {
  				res = WSAEWOULDBLOCK;
  				timeout = 1;
! 			} else if (res > 0) {
! 				if (FD_ISSET(s->sock_fd, &fds))
! 					/* The socket is in the writeable set - this
! 					   means connected */
! 					res = 0;
! 				else {
! 					/* As per MS docs, we need to call getsockopt()
! 					   to get the underlying error */
! 					int res_size = sizeof res;
! 					/* It must be in the exception set */
! 					assert(FD_ISSET(s->sock_fd, &fds_exc));
! 					if (0 == getsockopt(s->sock_fd, SOL_SOCKET, SO_ERROR, 
! 					                    (char *)&res, &res_size))
! 						/* getsockopt also clears WSAGetLastError,
! 						   so reset it back. */
! 						WSASetLastError(res);
! 					else
! 						res = WSAGetLastError();
! 				}
! 			}
  			/* else if (res < 0) an error occurred */
  		}



More information about the Python-checkins mailing list