diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -338,8 +338,14 @@ def connect(self, address): self.connected = False err = self.socket.connect_ex(address) - if err in (EINPROGRESS, EALREADY, EWOULDBLOCK) \ - or err == EINVAL and os.name in ('nt', 'ce'): + # connection being established asynchronously + if err in (EINPROGRESS, EWOULDBLOCK): + # EWOULDBLOCK may also be returned by winsock when calling connect + # while the connection attempt is in progress + if not self.addr: + self.addr = address + return + if (err == EALREADY or (err == EINVAL and os.name in ('nt', 'ce'))): return if err in (0, EISCONN): self.addr = address diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -777,6 +777,18 @@ finally: sock.close() + def test_addr_after_connect(self): + # Check that 'addr' is not None after connect (issue #XXX) + + class TestClient(BaseClient): + def handle_write(self): + if self.addr: + self.flag = True + + server = BaseServer(self.family, self.addr) + client = TestClient(self.family, server.address) + self.loop_waiting_for_flag(client) + class TestAPI_UseIPv4Sockets(BaseTestAPI): family = socket.AF_INET