mirror of https://github.com/python/cpython.git
bpo-31245: Asyncio unix socket datagram (#3164)
This commit is contained in:
parent
a2314283ff
commit
fe4ea9cf1e
|
@ -341,9 +341,10 @@ Creating connections
|
||||||
|
|
||||||
.. coroutinemethod:: AbstractEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, \*, family=0, proto=0, flags=0, reuse_address=None, reuse_port=None, allow_broadcast=None, sock=None)
|
.. coroutinemethod:: AbstractEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, \*, family=0, proto=0, flags=0, reuse_address=None, reuse_port=None, allow_broadcast=None, sock=None)
|
||||||
|
|
||||||
Create datagram connection: socket family :py:data:`~socket.AF_INET` or
|
Create datagram connection: socket family :py:data:`~socket.AF_INET`,
|
||||||
:py:data:`~socket.AF_INET6` depending on *host* (or *family* if specified),
|
:py:data:`~socket.AF_INET6` or :py:data:`~socket.AF_UNIX` depending on
|
||||||
socket type :py:data:`~socket.SOCK_DGRAM`. *protocol_factory* must be a
|
*host* (or *family* if specified), socket type
|
||||||
|
:py:data:`~socket.SOCK_DGRAM`. *protocol_factory* must be a
|
||||||
callable returning a :ref:`protocol <asyncio-protocol>` instance.
|
callable returning a :ref:`protocol <asyncio-protocol>` instance.
|
||||||
|
|
||||||
This method is a :ref:`coroutine <coroutine>` which will try to
|
This method is a :ref:`coroutine <coroutine>` which will try to
|
||||||
|
|
|
@ -859,6 +859,12 @@ def create_datagram_endpoint(self, protocol_factory,
|
||||||
if family == 0:
|
if family == 0:
|
||||||
raise ValueError('unexpected address family')
|
raise ValueError('unexpected address family')
|
||||||
addr_pairs_info = (((family, proto), (None, None)),)
|
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:
|
else:
|
||||||
# join address by (family, protocol)
|
# join address by (family, protocol)
|
||||||
addr_infos = collections.OrderedDict()
|
addr_infos = collections.OrderedDict()
|
||||||
|
|
|
@ -378,8 +378,8 @@ def create_datagram_endpoint(self, protocol_factory,
|
||||||
|
|
||||||
protocol_factory must be a callable returning a protocol instance.
|
protocol_factory must be a callable returning a protocol instance.
|
||||||
|
|
||||||
socket family AF_INET or socket.AF_INET6 depending on host (or
|
socket family AF_INET, socket.AF_INET6 or socket.AF_UNIX depending on
|
||||||
family if specified), socket type SOCK_DGRAM.
|
host (or family if specified), socket type SOCK_DGRAM.
|
||||||
|
|
||||||
reuse_address tells the kernel to reuse a local socket in
|
reuse_address tells the kernel to reuse a local socket in
|
||||||
TIME_WAIT state, without waiting for its natural timeout to
|
TIME_WAIT state, without waiting for its natural timeout to
|
||||||
|
|
|
@ -1528,6 +1528,17 @@ def test_create_datagram_endpoint_sock(self):
|
||||||
self.loop.run_until_complete(protocol.done)
|
self.loop.run_until_complete(protocol.done)
|
||||||
self.assertEqual('CLOSED', protocol.state)
|
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):
|
def test_create_datagram_endpoint_sock_sockopts(self):
|
||||||
class FakeSock:
|
class FakeSock:
|
||||||
type = socket.SOCK_DGRAM
|
type = socket.SOCK_DGRAM
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Added support for AF_UNIX socket in asyncio `create_datagram_endpoint`.
|
Loading…
Reference in New Issue