This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: socketmodule.c connection handling incorect on windows
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 2.4
process
Status: closed Resolution: out of date
Dependencies: 965036 Superseder:
Assigned To: Nosy List: ajaksu2, garth42, nnorwitz, tim.peters, troels
Priority: normal Keywords:

Created on 2003-07-25 15:01 by garth42, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Messages (6)
msg17330 - (view) Author: Garth Bushell (garth42) Date: 2003-07-25 15:01
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
msg17331 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-07-28 22:00
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.
msg17332 - (view) Author: Troels Walsted Hansen (troels) Date: 2004-06-02 13:59
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
msg17333 - (view) Author: Troels Walsted Hansen (troels) Date: 2004-06-08 08:48
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!
msg17334 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-04-24 01:26
Logged In: YES 
user_id=31435

Unassigned myself (no particular competence here, and short
on time).
msg81864 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-13 03:29
Fixed in r36739 according to #965036.
History
Date User Action Args
2022-04-10 16:10:12adminsetgithub: 38930
2009-02-13 03:29:43ajaksu2setstatus: open -> closed
nosy: + ajaksu2
messages: + msg81864
dependencies: + Fix for #777597 - socketmodule.c connection handling incorec
components: + Windows
type: behavior
resolution: out of date
2003-07-25 15:01:02garth42create