summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorQuentin Dawans <github@ovv.wtf>2017-10-30 13:43:02 (GMT)
committerYury Selivanov <yury@magic.io>2017-10-30 13:43:02 (GMT)
commitfe4ea9cf1ee04f5a60e4ed928d8624b95b031e18 (patch)
treea783b709a8856fdf34d540108e78803e6114c84b /Lib
parenta2314283ff87c65e1745a42c2f2b716b1a209128 (diff)
downloadcpython-fe4ea9cf1ee04f5a60e4ed928d8624b95b031e18.zip
cpython-fe4ea9cf1ee04f5a60e4ed928d8624b95b031e18.tar.gz
cpython-fe4ea9cf1ee04f5a60e4ed928d8624b95b031e18.tar.bz2
bpo-31245: Asyncio unix socket datagram (#3164)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/base_events.py6
-rw-r--r--Lib/asyncio/events.py4
-rw-r--r--Lib/test/test_asyncio/test_base_events.py11
3 files changed, 19 insertions, 2 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 33b8f48..2a5a4f9 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -859,6 +859,12 @@ class BaseEventLoop(events.AbstractEventLoop):
if family == 0:
raise ValueError('unexpected address family')
addr_pairs_info = (((family, proto), (None, None)),)
+ elif hasattr(socket, 'AF_UNIX') and family == socket.AF_UNIX:
+ for addr in (local_addr, remote_addr):
+ if addr is not None and not isistance(addr, str):
+ raise TypeError('string is expected')
+ addr_pairs_info = (((family, proto),
+ (local_addr, remote_addr)), )
else:
# join address by (family, protocol)
addr_infos = collections.OrderedDict()
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 0dbd92c..c2663c5 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -378,8 +378,8 @@ class AbstractEventLoop:
protocol_factory must be a callable returning a protocol instance.
- socket family AF_INET or socket.AF_INET6 depending on host (or
- family if specified), socket type SOCK_DGRAM.
+ socket family AF_INET, socket.AF_INET6 or socket.AF_UNIX depending on
+ host (or family if specified), socket type SOCK_DGRAM.
reuse_address tells the kernel to reuse a local socket in
TIME_WAIT state, without waiting for its natural timeout to
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 3f1ec65..a0ce9fa 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -1528,6 +1528,17 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
self.loop.run_until_complete(protocol.done)
self.assertEqual('CLOSED', protocol.state)
+ @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'No UNIX Sockets')
+ def test_create_datagram_endpoint_sock_unix(self):
+ fut = self.loop.create_datagram_endpoint(
+ lambda: MyDatagramProto(create_future=True, loop=self.loop),
+ family=socket.AF_UNIX)
+ transport, protocol = self.loop.run_until_complete(fut)
+ assert transport._sock.family == socket.AF_UNIX
+ transport.close()
+ self.loop.run_until_complete(protocol.done)
+ self.assertEqual('CLOSED', protocol.state)
+
def test_create_datagram_endpoint_sock_sockopts(self):
class FakeSock:
type = socket.SOCK_DGRAM