summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/selector_events.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-06-08 16:33:59 (GMT)
committerYury Selivanov <yury@magic.io>2016-06-08 16:33:59 (GMT)
commit552bf94648f09f4df68be9fc34a22f3b8441a67a (patch)
tree8789b0e0ce9787c99eabe21353ed6f65f31bf5f0 /Lib/asyncio/selector_events.py
parentb198c42bcb8a9d7ccf4da0218b6ad6adc5beadfb (diff)
parentf1c6fa986647791977d974bd43119b46a7a3cdbc (diff)
downloadcpython-552bf94648f09f4df68be9fc34a22f3b8441a67a.zip
cpython-552bf94648f09f4df68be9fc34a22f3b8441a67a.tar.gz
cpython-552bf94648f09f4df68be9fc34a22f3b8441a67a.tar.bz2
Merge 3.5 (issue #27136, asyncio)
Diffstat (limited to 'Lib/asyncio/selector_events.py')
-rw-r--r--Lib/asyncio/selector_events.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 29db06b..7ae532d 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -385,24 +385,28 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
def sock_connect(self, sock, address):
"""Connect to a remote socket at address.
- The address must be already resolved to avoid the trap of hanging the
- entire event loop when the address requires doing a DNS lookup. For
- example, it must be an IP address, not a hostname, for AF_INET and
- AF_INET6 address families. Use getaddrinfo() to resolve the hostname
- asynchronously.
-
This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
+
fut = self.create_future()
+ 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.add_done_callback(
+ lambda resolved: self._on_resolved(fut, sock, resolved))
+
+ return fut
+
+ def _on_resolved(self, fut, sock, resolved):
try:
- base_events._check_resolved_address(sock, address)
- except ValueError as err:
- fut.set_exception(err)
+ _, _, _, _, address = resolved.result()[0]
+ except Exception as exc:
+ fut.set_exception(exc)
else:
self._sock_connect(fut, sock, address)
- return fut
def _sock_connect(self, fut, sock, address):
fd = sock.fileno()