Skip to content

Commit

Permalink
Don't raise "requires a DNS lookup" error on Unix Domain Socket (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
pax0r authored and 1st1 committed Oct 30, 2018
1 parent 40ad257 commit 9fc3ca2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion tests/test_udp.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -155,6 +158,21 @@ def test_create_datagram_endpoint_sock(self):
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):

Expand Down
4 changes: 3 additions & 1 deletion uvloop/handles/udp.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import socket

cdef class UDPTransport(UVBaseTransport):

def __cinit__(self):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9fc3ca2

Please sign in to comment.