From 5895dc2f1ff21ccc69f7571582f90d52875d51a5 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 6 Aug 2017 20:39:14 +0200 Subject: [PATCH] Asyncore Windows error handling - windows behaves somewhat differently when using select --- src/network/asyncore_pollchoose.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/network/asyncore_pollchoose.py b/src/network/asyncore_pollchoose.py index ba156990..db6c1f4a 100644 --- a/src/network/asyncore_pollchoose.py +++ b/src/network/asyncore_pollchoose.py @@ -67,9 +67,14 @@ try: from errno import WSAENOTSOCK except (ImportError, AttributeError): WSAENOTSOCK = ENOTSOCK +try: + from errno import WSAECONNRESET +except (ImportError, AttributeError): + WSEACONNRESET = ECONNRESET _DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, - EBADF, ECONNREFUSED, EHOSTUNREACH, ENETUNREACH, ETIMEDOUT)) + EBADF, ECONNREFUSED, EHOSTUNREACH, ENETUNREACH, ETIMEDOUT, + WSAECONNRESET)) OP_READ = 1 OP_WRITE = 2 @@ -203,7 +208,10 @@ def select_poller(timeout=0.0, map=None): except KeyboardInterrupt: return except socket.error as err: - if err.args[0] in (EBADF, WSAENOTSOCK, EINTR): + if err.args[0] in (EBADF EINTR): + return + except Exception as err: + if err.args[0] in (WSAENOTSOCK, ): return for fd in random.sample(r, len(r)): @@ -686,6 +694,9 @@ class dispatcher: # like we would in a subclassed handle_read() that received no # data self.handle_close() + elif sys.platform.startswith("win"): + # async connect failed + self.handle_close() else: self.handle_expt()