Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socketmodule.c connection handling incorect on windows #38930

Closed
garth42 mannequin opened this issue Jul 25, 2003 · 6 comments
Closed

socketmodule.c connection handling incorect on windows #38930

garth42 mannequin opened this issue Jul 25, 2003 · 6 comments
Labels
OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@garth42
Copy link
Mannequin

garth42 mannequin commented Jul 25, 2003

BPO 777597
Nosy @tim-one, @devdanzin
Dependencies
  • bpo-965036: Fix for socketmodule.c connection handling incorect on windows #38930 - socketmodule.c connection handling incorec
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-02-13.03:29:43.195>
    created_at = <Date 2003-07-25.15:01:02.000>
    labels = ['type-bug', 'library', 'OS-windows']
    title = 'socketmodule.c connection handling incorect on windows'
    updated_at = <Date 2009-02-13.03:29:43.193>
    user = 'https://bugs.python.org/garth42'

    bugs.python.org fields:

    activity = <Date 2009-02-13.03:29:43.193>
    actor = 'ajaksu2'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-02-13.03:29:43.195>
    closer = 'ajaksu2'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2003-07-25.15:01:02.000>
    creator = 'garth42'
    dependencies = ['965036']
    files = []
    hgrepos = []
    issue_num = 777597
    keywords = []
    message_count = 6.0
    messages = ['17330', '17331', '17332', '17333', '17334', '81864']
    nosy_count = 5.0
    nosy_names = ['tim.peters', 'nnorwitz', 'troels', 'garth42', 'ajaksu2']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue777597'
    versions = ['Python 2.4']

    @garth42
    Copy link
    Mannequin Author

    garth42 mannequin commented Jul 25, 2003

    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

    @garth42 garth42 mannequin added stdlib Python modules in the Lib dir labels Jul 25, 2003
    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented Jul 28, 2003

    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.

    @troels
    Copy link
    Mannequin

    troels mannequin commented Jun 2, 2004

    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

    @troels
    Copy link
    Mannequin

    troels mannequin commented Jun 8, 2004

    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!

    @tim-one
    Copy link
    Member

    tim-one commented Apr 24, 2006

    Logged In: YES
    user_id=31435

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

    @devdanzin
    Copy link
    Mannequin

    devdanzin mannequin commented Feb 13, 2009

    Fixed in r36739 according to bpo-965036.

    @devdanzin devdanzin mannequin added the OS-windows label Feb 13, 2009
    @devdanzin devdanzin mannequin closed this as completed Feb 13, 2009
    @devdanzin devdanzin mannequin added type-bug An unexpected behavior, bug, or error OS-windows labels Feb 13, 2009
    @devdanzin devdanzin mannequin closed this as completed Feb 13, 2009
    @devdanzin devdanzin mannequin added the type-bug An unexpected behavior, bug, or error label Feb 13, 2009
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant