[Python-bugs-list] [ python-Bugs-777597 ] socketmodule.c connection handling incorect on windows

SourceForge.net noreply@sourceforge.net
Fri, 25 Jul 2003 08:01:02 -0700


Bugs item #777597, was opened at 2003-07-25 15:01
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=777597&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Garth Bushell (garth42)
Assigned to: Nobody/Anonymous (nobody)
Summary: socketmodule.c connection handling incorect on windows

Initial Comment:
The socketmodule.c code does not handle connection
refused correctly. This is due to a different of
operation on windows of select. The offending code is
in internal_connect in the MS_WINDOWS ifdef. The code
in should test  exceptfds to check for connecttion
refused. If this is so itshould call
getsockopt(SOL_SOCKET, SO_ERROR,..) to get the error
status. (Source microsoft Platform SDK)
The suggested fix is shown below (untested)

#ifdef MS_WINDOWS

f (s->sock_timeout > 0.0) {
    if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK) {
	/* This is a mess.  Best solution: trust select */
	fd_set exfds;
	struct timeval tv;
	tv.tv_sec = (int)s->sock_timeout;
	tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
	FD_ZERO(&exfds);
	FD_SET(s->sock_fd, &exfds);
	/* Platform SDK says so */
	res = select(s->sock_fd+1, NULL, NULL, &exfds, &tv);
	if (res > 0) { 
	    if( FD_ISSET( &exfds ) ) {
		/* Get the real reason */
	
getsockopt(s->sock_fd,SOL_SOCKET,SO_ERROR,(char*)&res,sizeof(res));
	    } else {
		/* God knows how we got here */
		res = 0;
	    }
	} else if( res == 0 ) {
	    res = WSAEWOULDBLOCK;
	} else
	{ 
	    /* Not sure we should return the erro from select? */
	    res =  WSAGetLastError();
	}
    }
} else if (res < 0)
    res = WSAGetLastError();

#else

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=777597&group_id=5470