From 9fc3ca2af435f9ed74a96001397f515baa67e107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Biernacki?= Date: Thu, 18 Oct 2018 02:24:47 +0200 Subject: [PATCH] Don't raise "requires a DNS lookup" error on Unix Domain Socket (#204) --- tests/test_udp.py | 20 +++++++++++++++++++- uvloop/handles/udp.pyx | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/test_udp.py b/tests/test_udp.py index 1e5be9b..27105dd 100644 --- a/tests/test_udp.py +++ b/tests/test_udp.py @@ -1,7 +1,10 @@ import asyncio +import os import socket -import unittest import sys +import tempfile +import unittest +import uuid from uvloop import _testbase as tb @@ -155,6 +158,21 @@ class _TestUDP: tr.close() self.loop.run_until_complete(pr.done) + @unittest.skipIf(sys.version_info < (3, 5, 1), + "asyncio in 3.5.0 doesn't have the 'sock' argument") + def test_create_datagram_endpoint_sock_unix_domain(self): + tmp_file = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) + sock = socket.socket(socket.AF_UNIX, type=socket.SOCK_DGRAM) + sock.bind(tmp_file) + + with sock: + f = self.loop.create_datagram_endpoint( + lambda: MyDatagramProto(loop=self.loop), sock=sock) + tr, pr = self.loop.run_until_complete(f) + self.assertIsInstance(pr, MyDatagramProto) + tr.sendto(b'HELLO', tmp_file) + tr.close() + self.loop.run_until_complete(pr.done) class Test_UV_UDP(_TestUDP, tb.UVTestCase): diff --git a/uvloop/handles/udp.pyx b/uvloop/handles/udp.pyx index f9d8f6f..81ad198 100644 --- a/uvloop/handles/udp.pyx +++ b/uvloop/handles/udp.pyx @@ -1,3 +1,5 @@ +import socket + cdef class UDPTransport(UVBaseTransport): def __cinit__(self): @@ -141,7 +143,7 @@ cdef class UDPTransport(UVBaseTransport): raise ValueError( 'Invalid address: must be None or {}'.format(self.address)) - if addr is not None: + if addr is not None and self.sock.family != socket.AF_UNIX: addrinfo = __static_getaddrinfo_pyaddr( addr[0], addr[1], uv.AF_UNSPEC, self.sock.type, self.sock.proto, 0)