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

SourceForge.net noreply at sourceforge.net
Mon Apr 24 03:26:25 CEST 2006


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

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
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

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

>Comment By: Tim Peters (tim_one)
Date: 2006-04-23 21:26

Message:
Logged In: YES 
user_id=31435

Unassigned myself (no particular competence here, and short
on time).

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

Comment By: Troels Walsted Hansen (troels)
Date: 2004-06-08 04:48

Message:
Logged In: YES 
user_id=32863

http://python.org/sf/965036 has been updated with a fixed
and tested patch. Could somebody review and apply it? Thanks!


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

Comment By: Troels Walsted Hansen (troels)
Date: 2004-06-02 09:59

Message:
Logged In: YES 
user_id=32863

I have turned Garth's code into a patch versus Python 2.3.4.
I don't believe the fix is correct and complete, but it
should serve as a starting point. Patch is in
http://python.org/sf/965036


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

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-07-28 18:00

Message:
Logged In: YES 
user_id=33168

Garth could you produce a patch against 2.3c2 with your
selected change and test it?  It would help us a lot as we
are all very overloaded.  Thanks.

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

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


More information about the Python-bugs-list mailing list