Skip to content

Commit 9fc3ca2

Browse files
pax0r1st1
authored andcommitted
Don't raise "requires a DNS lookup" error on Unix Domain Socket (#204)
1 parent 40ad257 commit 9fc3ca2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/test_udp.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import asyncio
2+
import os
23
import socket
3-
import unittest
44
import sys
5+
import tempfile
6+
import unittest
7+
import uuid
58

69
from uvloop import _testbase as tb
710

@@ -155,6 +158,21 @@ def test_create_datagram_endpoint_sock(self):
155158
tr.close()
156159
self.loop.run_until_complete(pr.done)
157160

161+
@unittest.skipIf(sys.version_info < (3, 5, 1),
162+
"asyncio in 3.5.0 doesn't have the 'sock' argument")
163+
def test_create_datagram_endpoint_sock_unix_domain(self):
164+
tmp_file = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
165+
sock = socket.socket(socket.AF_UNIX, type=socket.SOCK_DGRAM)
166+
sock.bind(tmp_file)
167+
168+
with sock:
169+
f = self.loop.create_datagram_endpoint(
170+
lambda: MyDatagramProto(loop=self.loop), sock=sock)
171+
tr, pr = self.loop.run_until_complete(f)
172+
self.assertIsInstance(pr, MyDatagramProto)
173+
tr.sendto(b'HELLO', tmp_file)
174+
tr.close()
175+
self.loop.run_until_complete(pr.done)
158176

159177
class Test_UV_UDP(_TestUDP, tb.UVTestCase):
160178

uvloop/handles/udp.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import socket
2+
13
cdef class UDPTransport(UVBaseTransport):
24

35
def __cinit__(self):
@@ -141,7 +143,7 @@ cdef class UDPTransport(UVBaseTransport):
141143
raise ValueError(
142144
'Invalid address: must be None or {}'.format(self.address))
143145

144-
if addr is not None:
146+
if addr is not None and self.sock.family != socket.AF_UNIX:
145147
addrinfo = __static_getaddrinfo_pyaddr(
146148
addr[0], addr[1],
147149
uv.AF_UNSPEC, self.sock.type, self.sock.proto, 0)

0 commit comments

Comments
 (0)