8000 Fix loop.getaddrinfo() and tests by fantix · Pull Request #495 · MagicStack/uvloop · GitHub
[go: up one dir, main page]

Skip to content

Fix loop.getaddrinfo() and tests #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CRF: improve readibility
  • Loading branch information
fantix committed Sep 11, 2022
commit 0b27ec4ee601948f7288e1f6b804f40db1c38d23
28 changes: 20 additions & 8 deletions uvloop/dns.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,27 @@ cdef __static_getaddrinfo(object host, object port,
return (family, type, proto)


# This bitmask is used in __static_getaddrinfo_pyaddr() to manage
# if ai_canonname should be set if AI_CANONNAME flag is set.
# This bitmask is lazily set in loop.getaddrinfo() to make sure that
# This flag is used in __static_getaddrinfo_pyaddr() to manage
# if ai_canonname should be returned when AI_CANONNAME flag is set,
# because its behavior varies in different libc implementations (see #494).
# This flag is lazily set in loop.getaddrinfo() to make sure that
# __static_getaddrinfo_pyaddr() behaves consistently as libc getaddrinfo().
# 1 << 0 : If 1 << 1 is set
# 1 << 1 : If ai_canonname should be set if AI_CANONNAME is set
# 1 << 2 : If 1 << 3 is set
# 1 << 3 : If ai_canonname should be set if AI_CANONNAME is not set
cdef int __static_getaddrinfo_canonname_mode = 0

# Bitmasks for __static_getaddrinfo_canonname_mode:

# If STATIC_GETADDRINFO_CANONNAME_ON_RETURN is set
cdef int STATIC_GETADDRINFO_CANONNAME_ON_BEHAVIOR_SET = 1 << 0

# If ai_canonname should be returned when AI_CANONNAME is set
cdef int STATIC_GETADDRINFO_CANONNAME_ON_RETURN = 1 << 1

# If STATIC_GETADDRINFO_CANONNAME_OFF_RETURN is set
cdef int STATIC_GETADDRINFO_CANONNAME_OFF_BEHAVIOR_SET = 1 << 2

# If ai_canonname should be returned when AI_CANONNAME is not set
cdef int STATIC_GETADDRINFO_CANONNAME_OFF_RETURN = 1 << 3


cdef __static_getaddrinfo_pyaddr(object host, object port,
int family, int type,
Expand All @@ -257,7 +268,8 @@ cdef __static_getaddrinfo_pyaddr(object host, object port,
return

if __static_getaddrinfo_canonname_mode & (
1 << 1 if flags & socket_AI_CANONNAME else 1 << 3
STATIC_GETADDRINFO_CANONNAME_ON_RETURN if flags & socket_AI_CANONNAME
else STATIC_GETADDRINFO_CANONNAME_OFF_RETURN
):
if isinstance(host, str):
canon_name = host
Expand Down
27 changes: 18 additions & 9 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1529,23 +1529,32 @@ cdef class Loop:
type, proto, flags)
if addr is not None:
if __static_getaddrinfo_canonname_mode & (
1 << 0 if flags & socket_AI_CANONNAME else 1 << 2
STATIC_GETADDRINFO_CANONNAME_ON_BEHAVIOR_SET
if flags & socket_AI_CANONNAME
else STATIC_GETADDRINFO_CANONNAME_OFF_BEHAVIOR_SET
):
return [addr]

rv = await self._getaddrinfo(
host, port, family, type, proto, flags, 1)

_af, _type, _proto, canon_name, _addr = rv[0]
if flags & socket_AI_CANONNAME:
if rv[0][3]:
__static_getaddrinfo_canonname_mode |= 1 << 0 | 1 << 1
else:
__static_getaddrinfo_canonname_mode |= 1 << 0
__static_getaddrinfo_canonname_mode |= (
STATIC_GETADDRINFO_CANONNAME_ON_BEHAVIOR_SET
)
if canon_name:
__static_getaddrinfo_canonname_mode |= (
STATIC_GETADDRINFO_CANONNAME_ON_RETURN
)
else:
if rv[0][3]:
__static_getaddrinfo_canonname_mode |= 1 << 2 | 1 << 3
else:
__static_getaddrinfo_canonname_mode |= 1 << 2
__static_getaddrinfo_canonname_mode |= (
STATIC_GETADDRINFO_CANONNAME_OFF_BEHAVIOR_SET
)
if canon_name:
__static_getaddrinfo_canonname_mode |= (
STATIC_GETADDRINFO_CANONNAME_OFF_RETURN
)

return rv

Expand Down
0