possible error in socketmodule / asyncore on win32

Discussion in 'Python' started by Garth, Jul 24, 2003.

  1. Garth

    Garth Guest

    Hi,

    I think there's an error in ther socketmodule.c code
    under windows. The code in internal connect should test
    exceptfds to check for connecttion refused. If this is so it
    should call getsockopt(SOL_SOCKET, SO_ERROR,..) to get the error
    status. (Source microsoft Platform SDK)

    If this isn't then the asynccore module fails on windows and never
    returns connection refused.

    The code should probably look something like this (untested)

    if (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
    {
    res = 0;
    }
    }
    else if (res > 0)
    {
    res = WSAGetLastError();
    }
    }
    } else if (res < 0)
    res = WSAGetLastError();

    This still doesn't solve the problem in asyncore as it doesn't test
    exfss. I guess it should test exfs if it's not connected (again not tested)

    def poll(timeout=0.0, map=None):
    if map is None:
    map = socket_map
    if map:
    r = []; w = []; e = []
    for fd, obj in map.items():
    if obj.readable():
    r.append(fd)
    if obj.writable():
    w.append(fd)

    if sys.platform == 'win32':
    if not obj.connected:
    e.append(fd)
    if [] == r == w == e:
    time.sleep(timeout)
    else:
    try:
    r, w, e = select.select(r, w, e, timeout)
    except select.error, err:
    if err[0] != EINTR:
    raise
    else:
    return

    if sys.platform == 'win32':
    for fd in e:
    obj = map.get(fd)
    if obj is None:
    continue
    errno = fs.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
    raise socket.error,(errno,socketerrorTab[error])

    for fd in r:
    obj = map.get(fd)
    if obj is None:
    continue
    read(obj)

    for fd in w:
    obj = map.get(fd)
    if obj is None:
    continue
    write(obj)

    Not really sure where to report this so I'm posting here.

    This is all against 2.3c1

    (Cheers to all for a wicked language.)

    Garth
     
    Garth, Jul 24, 2003
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Lyman
    Replies:
    0
    Views:
    811
    Alex Lyman
    Mar 7, 2004
  2. Java and Swing
    Replies:
    1
    Views:
    856
    Chris Lambacher
    Oct 24, 2005
  3. viktough
    Replies:
    0
    Views:
    452
    viktough
    Jul 19, 2006
  4. rcmn
    Replies:
    1
    Views:
    519
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Nov 6, 2006
  5. jacopo mondi

    hoe to build a patched socketmodule.c

    jacopo mondi, Jul 9, 2009, in forum: Python
    Replies:
    4
    Views:
    639
    jacopo mondi
    Jul 11, 2009
  6. Michael Edmonson

    Win32::SAPI4 question (Win32 events and Perl)

    Michael Edmonson, Feb 28, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    326
    Michael Edmonson
    Feb 28, 2004
  7. Jim Roberts
    Replies:
    7
    Views:
    439
    Bart Lateur
    Jan 4, 2006
  8. Ziv Tepman
    Replies:
    0
    Views:
    247
    Ziv Tepman
    Jan 21, 2014
Loading...