Index: asyncore.py =================================================================== --- asyncore.py (revision 142053) +++ asyncore.py (revision 142057) @@ -59,7 +59,28 @@ _DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, EBADF)) +_INTERRUPTED = frozenset((EINTR,)) +_NOTCONNECTED = frozenset((ENOTCONN, EINVAL)) +_NOMINAL_CONNECT_ERRORS = frozenset((EINPROGRESS, EALREADY, EWOULDBLOCK)) +_IS_CONNECTED = frozenset((0, EISCONN,)) +_NO_CLIENT_ACCEPT_ERRORS = frozenset((EWOULDBLOCK, ECONNABORTED, EAGAIN)) +_WOULDBLOCK = frozenset((EWOULDBLOCK,)) +_IGNORED_CLOSE_ERRORS = frozenset((ENOTCONN, EBADF)) +_BAD_FILE_DESCRIPTOR = frozenset((EBADF,)) +if os.name in ('nt', 'ce'): + from errno import WSAEALREADY, WSAEINPROGRESS, WSAEWOULDBLOCK, WSAECONNRESET, WSAEINVAL, \ + WSAENOTCONN, WSAESHUTDOWN, WSAEINTR, WSAEISCONN, WSAEBADF, WSAECONNABORTED + _DISCONNECTED = _DISCONNECTED.union((WSAECONNRESET, WSAENOTCONN, WSAESHUTDOWN, WSAECONNABORTED, WSAEBADF)) + _INTERRUPTED = _INTERRUPTED.union((WSAEINTR,)) + _NOTCONNECTED = _NOTCONNECTED.union((WSAENOTCONN, WSAEINVAL)) + _NOMINAL_CONNECT_ERRORS = _NOMINAL_CONNECT_ERRORS.union((EINVAL, WSAEINVAL, WSAEINPROGRESS, WSAEALREADY, WSAEWOULDBLOCK)) + _IS_CONNECTED = _IS_CONNECTED.union((WSAEISCONN,)) + _NO_CLIENT_ACCEPT_ERRORS = _NO_CLIENT_ACCEPT_ERRORS.union((WSAEWOULDBLOCK, WSAECONNABORTED)) + _WOULDBLOCK = _WOULDBLOCK.union((WSAEWOULDBLOCK,)) + _IGNORED_CLOSE_ERRORS = _IGNORED_CLOSE_ERRORS.union((WSAENOTCONN, WSAEBADF)) + _BAD_FILE_DESCRIPTOR = _BAD_FILE_DESCRIPTOR.union((WSAEBADF,)) + try: socket_map except NameError: @@ -144,7 +165,7 @@ try: r, w, e = select.select(r, w, e, timeout) except select.error, err: - if err.args[0] != EINTR: + if err.args[0] not in _INTERRUPTED: raise else: return @@ -191,7 +212,7 @@ try: r = pollster.poll(timeout) except select.error, err: - if err.args[0] != EINTR: + if err.args[0] not in _INTERRUPTED: raise r = [] for fd, flags in r: @@ -249,7 +270,7 @@ try: self.addr = sock.getpeername() except socket.error, err: - if err.args[0] in (ENOTCONN, EINVAL): + if err.args[0] in _NOTCONNECTED: # To handle the case where we got an unconnected # socket. self.connected = False @@ -345,11 +366,10 @@ self.connected = False self.connecting = True err = self.socket.connect_ex(address) - if err in (EINPROGRESS, EALREADY, EWOULDBLOCK) \ - or err == EINVAL and os.name in ('nt', 'ce'): + if err in _NOMINAL_CONNECT_ERRORS: self.addr = address return - if err in (0, EISCONN): + if err in _IS_CONNECTED: self.addr = address self.handle_connect_event() else: @@ -362,7 +382,7 @@ except TypeError: return None except socket.error as why: - if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN): + if why.args[0] in _NO_CLIENT_ACCEPT_ERRORS: return None else: raise @@ -374,7 +394,7 @@ result = self.socket.send(data) return result except socket.error, why: - if why.args[0] == EWOULDBLOCK: + if why.args[0] in _WOULDBLOCK: return 0 elif why.args[0] in _DISCONNECTED: self.handle_close() @@ -408,7 +428,7 @@ try: self.socket.close() except socket.error, why: - if why.args[0] not in (ENOTCONN, EBADF): + if why.args[0] not in _IGNORED_CLOSE_ERRORS: raise # cheap inheritance, used to pass all other attribute @@ -580,7 +600,7 @@ try: x.close() except OSError, x: - if x.args[0] == EBADF: + if x.args[0] in _BAD_FILE_DESCRIPTOR: pass elif not ignore_all: raise