From 63bf48768867a7421f8ccb956fe77f295bfd2742 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 28 Jun 2016 11:00:22 -0400 Subject: [PATCH] asyncio: Use socket specs for getaddrinfo() in sock_connect() Patch by Martin Richard. GH PR #365. --- Lib/asyncio/selector_events.py | 3 ++- Lib/test/test_asyncio/test_selector_events.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 9564d01dfa6..ed2b4d756fe 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -394,7 +394,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): if hasattr(socket, 'AF_UNIX') and sock.family == socket.AF_UNIX: self._sock_connect(fut, sock, address) else: - resolved = base_events._ensure_resolved(address, loop=self) + resolved = base_events._ensure_resolved( + address, family=sock.family, proto=sock.proto, loop=self) resolved.add_done_callback( lambda resolved: self._on_resolved(fut, sock, resolved)) diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py index 5dc6ff8e66d..ff71c218bb1 100644 --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -373,6 +373,17 @@ class BaseSelectorEventLoopTests(test_utils.TestCase): self.loop.run_until_complete(fut) self.assertTrue(self.loop.remove_writer.called) + def test_sock_connect_resolve_using_socket_params(self): + addr = ('need-resolution.com', 8080) + sock = test_utils.mock_nonblocking_socket() + self.loop.getaddrinfo = mock.Mock() + self.loop.sock_connect(sock, addr) + while not self.loop.getaddrinfo.called: + self.loop._run_once() + self.loop.getaddrinfo.assert_called_with( + *addr, type=sock.type, family=sock.family, proto=sock.proto, + flags=0) + def test__sock_connect(self): f = asyncio.Future(loop=self.loop)