From b365be80a6c16cb49f04cf3afa6db06340da5b93 Mon Sep 17 00:00:00 2001 From: Vizonex Date: Thu, 1 Oct 2026 10:41:11 -0500 Subject: [PATCH] use newly compiled Future objects on dns related calls --- winloop/_version.py | 2 +- winloop/loop.pxd | 4 ++-- winloop/loop.pyx | 21 +++++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/winloop/_version.py b/winloop/_version.py index d49ea6f..fc14bce 100644 --- a/winloop/_version.py +++ b/winloop/_version.py @@ -10,4 +10,4 @@ # supported platforms, publish the packages on PyPI, merge the PR # to the target branch, create a Git tag pointing to the commit. -__version__ = '0.6.4' +__version__ = '0.7.0' diff --git a/winloop/loop.pxd b/winloop/loop.pxd index e70d923..c942d51 100644 --- a/winloop/loop.pxd +++ b/winloop/loop.pxd @@ -159,12 +159,12 @@ cdef class Loop: cdef inline _check_closed(self) cdef inline _check_thread(self) - cdef _getaddrinfo(self, object host, object port, + cdef Future _getaddrinfo(self, object host, object port, int family, int type, int proto, int flags, int unpack) - cdef _getnameinfo(self, system.sockaddr *addr, int flags) + cdef Future _getnameinfo(self, system.sockaddr *addr, int flags) cdef _track_transport(self, UVBaseTransport transport) cdef _fileobj_to_fd(self, fileobj) diff --git a/winloop/loop.pyx b/winloop/loop.pyx index 8c28ab8..26ac3fb 100644 --- a/winloop/loop.pyx +++ b/winloop/loop.pyx @@ -877,6 +877,7 @@ cdef class Loop: return result + # TODO: signature of bint or int return except -1 would be better here. cdef _has_writer(self, fileobj): cdef: UVPoll poll @@ -891,11 +892,13 @@ cdef class Loop: return poll.is_writing() - cdef _getaddrinfo(self, object host, object port, + cdef Future _getaddrinfo(self, object host, object port, int family, int type, int proto, int flags, int unpack): + cdef Future fut + if isinstance(port, str): port = port.encode() elif isinstance(port, int): @@ -909,8 +912,14 @@ cdef class Loop: if not isinstance(host, bytes): raise TypeError('host must be a str or bytes') - fut = self._new_future() + # TODO: Use _new_future to return compiled Future objects + # in a later update (0.8.0) + fut = Future(loop=self) + # TODO: Sometime before or after 0.8.0, + # Let's Convert this callback to a ctypedef callback + # for added performance. + # example: ctypedef int (*addrinfo_callback)(Future fut, object result) except -1 def callback(result): if AddrInfo.isinstance(result): try: @@ -933,10 +942,14 @@ cdef class Loop: AddrInfoRequest(self, host, port, family, type, proto, flags, callback) return fut - cdef _getnameinfo(self, system.sockaddr *addr, int flags): + cdef Future _getnameinfo(self, system.sockaddr *addr, int flags): cdef NameInfoRequest nr - fut = self._new_future() + cdef Future fut + fut = Future(loop=self) + # Ditto of 0.8.0's TODO list: + # Something like ctypedef int (*nameinfo_callback)(Future, object) except -1 + # would be sufficient. def callback(result): if isinstance(result, tuple): fut.set_result(result)