Fix create_datagram_endpoint to work with AF_INET6 and no local_addr

A fix for #98.
This commit is contained in:
Yury Selivanov 2017-08-28 13:37:19 -04:00
parent 490c410321
commit 45e177555d
2 changed files with 22 additions and 1 deletions

View File

@ -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)

View File

@ -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 = (<AddrInfo>lads).data
while lai is not NULL: