From 45e177555d78066b9d7fa01c0049d89e43b7f794 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 28 Aug 2017 13:37:19 -0400 Subject: [PATCH] Fix create_datagram_endpoint to work with AF_INET6 and no local_addr A fix for #98. --- tests/test_udp.py | 18 ++++++++++++++++++ uvloop/loop.pyx | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/test_udp.py b/tests/test_udp.py index 545d595..fe3c4ec 100644 --- a/tests/test_udp.py +++ b/tests/test_udp.py @@ -97,6 +97,24 @@ class _TestUDP: server.transport.close() self.loop.run_until_complete(server.done) + def test_create_datagram_endpoint_ipv6_family(self): + class TestMyDatagramProto(MyDatagramProto): + def __init__(inner_self): + super().__init__(loop=self.loop) + + def datagram_received(self, data, addr): + super().datagram_received(data, addr) + self.transport.sendto(b'resp:' + data, addr) + + coro = self.loop.create_datagram_endpoint( + TestMyDatagramProto, local_addr=None, family=socket.AF_INET6) + s_transport = None + try: + s_transport, server = self.loop.run_until_complete(coro) + finally: + if s_transport: + s_transport.close() + def test_create_datagram_endpoint_sock(self): sock = None local_address = ('127.0.0.1', 0) diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index be5c8d2..256ef53 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -2433,7 +2433,10 @@ cdef class Loop: self._sock_set_reuseport(udp._fileno()) socket = udp._get_socket() - socket.bind(('0.0.0.0', 0)) + if family == uv.AF_INET6: + socket.bind(('::', 0)) + else: + socket.bind(('0.0.0.0', 0)) else: lai = (lads).data while lai is not NULL: