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. Advertising

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. viktough
    Replies:
    0
    Views:
    368
    viktough
    Jul 19, 2006
  2. jacopo mondi

    hoe to build a patched socketmodule.c

    jacopo mondi, Jul 9, 2009, in forum: Python
    Replies:
    4
    Views:
    535
    jacopo mondi
    Jul 11, 2009
  3. Ziv Tepman
    Replies:
    0
    Views:
    87
    Ziv Tepman
    Jan 21, 2014
  4. Ziv Tepman
    Replies:
    0
    Views:
    104
    Ziv Tepman
    Jan 21, 2014
  5. Chris Angelico
    Replies:
    0
    Views:
    93
    Chris Angelico
    Jan 21, 2014
Loading...

Share This Page