Skip to content

Commit c2b65bc

Browse files
committed
Start using high-performance uv_udp_t handle again
* Upgrade to libuv v1.28.0. This is the new minimal supported libuv version. * Switch from using uv_poll_t to uv_udp_t. This leads to significant performance improvements.
1 parent e3b00b8 commit c2b65bc

File tree

8 files changed

+501
-247
lines changed

8 files changed

+501
-247
lines changed

uvloop/dns.pyx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ cdef __convert_pyaddr_to_sockaddr(int family, object addr,
7070
int addr_len
7171
int scope_id = 0
7272
int flowinfo = 0
73+
char *buf
74+
Py_ssize_t buflen
7375

7476
if family == uv.AF_INET:
7577
if not isinstance(addr, tuple):
@@ -126,9 +128,24 @@ cdef __convert_pyaddr_to_sockaddr(int family, object addr,
126128
(<system.sockaddr_in6*>res).sin6_flowinfo = flowinfo
127129
(<system.sockaddr_in6*>res).sin6_scope_id = scope_id
128130

131+
elif family == uv.AF_UNIX:
132+
if isinstance(addr, str):
133+
addr = addr.encode(sys_getfilesystemencoding())
134+
elif not isinstance(addr, bytes):
135+
raise TypeError('AF_UNIX address must be a str or a bytes object')
136+
137+
PyBytes_AsStringAndSize(addr, &buf, &buflen)
138+
if buflen > 107:
139+
raise ValueError(
140+
f'unix socket path {addr!r} is longer than 107 characters')
141+
142+
memset(res, 0, sizeof(system.sockaddr_un))
143+
(<system.sockaddr_un*>res).sun_family = uv.AF_UNIX
144+
memcpy((<system.sockaddr_un*>res).sun_path, buf, buflen)
145+
129146
else:
130147
raise ValueError(
131-
'epected AF_INET or AF_INET6 family, got {}'.format(family))
148+
f'epected AF_INET, AF_INET6, or AF_UNIX family, got {family}')
132149

133150

134151
cdef __static_getaddrinfo(object host, object port,

uvloop/handles/udp.pxd

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
cdef class UDPTransport(UVBaseTransport):
22
cdef:
3-
object sock
4-
int sock_family
5-
int sock_proto
6-
int sock_type
7-
UVPoll poll
8-
object address
9-
object buffer
3+
bint __receiving
4+
int _family
105

11-
cdef _init(self, Loop loop, object sock, object r_addr)
6+
cdef _init(self, Loop loop, unsigned int family)
127

13-
cdef _on_read_ready(self)
14-
cdef _on_write_ready(self)
8+
cdef _connect(self, system.sockaddr* addr, size_t addr_len)
159

16-
@staticmethod
17-
cdef UDPTransport new(Loop loop, object sock, object r_addr)
10+
cdef _bind(self, system.sockaddr* addr, bint reuse_addr)
11+
cdef open(self, int family, int sockfd)
12+
cdef _set_broadcast(self, bint on)
13+
14+
cdef inline __receiving_started(self)
15+
cdef inline __receiving_stopped(self)
16+
17+
cdef _send(self, object data, object addr)
18+
19+
cdef _on_receive(self, bytes data, object exc, object addr)
20+
cdef _on_sent(self, object exc)

0 commit comments

Comments
 (0)