Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d904c238
Commit
d904c238
authored
Jun 28, 2018
by
Yury Selivanov
Committed by
GitHub
Jun 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-27500: Fix static version of getaddrinfo to resolve IPv6 (GH-7993)
parent
41cb0bae
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
6 deletions
+33
-6
Lib/asyncio/base_events.py
Lib/asyncio/base_events.py
+10
-4
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_base_events.py
+22
-2
Misc/NEWS.d/next/Library/2018-06-28-13-00-12.bpo-27500._s1gZ5.rst
...S.d/next/Library/2018-06-28-13-00-12.bpo-27500._s1gZ5.rst
+1
-0
No files found.
Lib/asyncio/base_events.py
View file @
d904c238
...
...
@@ -61,6 +61,8 @@ _MIN_CANCELLED_TIMER_HANDLES_FRACTION = 0.5
_FATAL_ERROR_IGNORE
=
(
BrokenPipeError
,
ConnectionResetError
,
ConnectionAbortedError
)
_HAS_IPv6
=
hasattr
(
socket
,
'AF_INET6'
)
def
_format_handle
(
handle
):
cb
=
handle
.
_callback
...
...
@@ -123,7 +125,7 @@ def _ipaddr_info(host, port, family, type, proto):
if
family
==
socket
.
AF_UNSPEC
:
afs
=
[
socket
.
AF_INET
]
if
hasattr
(
socket
,
'AF_INET6'
)
:
if
_HAS_IPv6
:
afs
.
append
(
socket
.
AF_INET6
)
else
:
afs
=
[
family
]
...
...
@@ -139,6 +141,9 @@ def _ipaddr_info(host, port, family, type, proto):
try
:
socket
.
inet_pton
(
af
,
host
)
# The host has already been resolved.
if
_HAS_IPv6
and
af
==
socket
.
AF_INET6
:
return
af
,
type
,
proto
,
''
,
(
host
,
port
,
0
,
0
)
else
:
return
af
,
type
,
proto
,
''
,
(
host
,
port
)
except
OSError
:
pass
...
...
@@ -1309,7 +1314,6 @@ class BaseEventLoop(events.AbstractEventLoop):
raise
ValueError
(
'host/port and sock can not be specified at the same time'
)
AF_INET6
=
getattr
(
socket
,
'AF_INET6'
,
0
)
if
reuse_address
is
None
:
reuse_address
=
os
.
name
==
'posix'
and
sys
.
platform
!=
'cygwin'
sockets
=
[]
...
...
@@ -1349,7 +1353,9 @@ class BaseEventLoop(events.AbstractEventLoop):
# Disable IPv4/IPv6 dual stack support (enabled by
# default on Linux) which makes a single socket
# listen on both address families.
if
af
==
AF_INET6
and
hasattr
(
socket
,
'IPPROTO_IPV6'
):
if
(
_HAS_IPv6
and
af
==
socket
.
AF_INET6
and
hasattr
(
socket
,
'IPPROTO_IPV6'
)):
sock
.
setsockopt
(
socket
.
IPPROTO_IPV6
,
socket
.
IPV6_V6ONLY
,
True
)
...
...
Lib/test/test_asyncio/test_base_events.py
View file @
d904c238
...
...
@@ -97,11 +97,11 @@ class BaseEventTests(test_utils.TestCase):
base_events
.
_ipaddr_info
(
'1.2.3.4'
,
1
,
INET6
,
STREAM
,
TCP
))
self
.
assertEqual
(
(
INET6
,
STREAM
,
TCP
,
''
,
(
'::3'
,
1
)),
(
INET6
,
STREAM
,
TCP
,
''
,
(
'::3'
,
1
,
0
,
0
)),
base_events
.
_ipaddr_info
(
'::3'
,
1
,
INET6
,
STREAM
,
TCP
))
self
.
assertEqual
(
(
INET6
,
STREAM
,
TCP
,
''
,
(
'::3'
,
1
)),
(
INET6
,
STREAM
,
TCP
,
''
,
(
'::3'
,
1
,
0
,
0
)),
base_events
.
_ipaddr_info
(
'::3'
,
1
,
UNSPEC
,
STREAM
,
TCP
))
# IPv6 address with family IPv4.
...
...
@@ -1077,6 +1077,26 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
srv
.
close
()
self
.
loop
.
run_until_complete
(
srv
.
wait_closed
())
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'AF_INET6'
),
'no IPv6 support'
)
def
test_create_server_ipv6
(
self
):
async
def
main
():
srv
=
await
asyncio
.
start_server
(
lambda
:
None
,
'::1'
,
0
,
loop
=
self
.
loop
)
try
:
self
.
assertGreater
(
len
(
srv
.
sockets
),
0
)
finally
:
srv
.
close
()
await
srv
.
wait_closed
()
try
:
self
.
loop
.
run_until_complete
(
main
())
except
OSError
as
ex
:
if
(
hasattr
(
errno
,
'EADDRNOTAVAIL'
)
and
ex
.
errno
==
errno
.
EADDRNOTAVAIL
):
self
.
skipTest
(
'failed to bind to ::1'
)
else
:
raise
def
test_create_datagram_endpoint_wrong_sock
(
self
):
sock
=
socket
.
socket
(
socket
.
AF_INET
)
with
sock
:
...
...
Misc/NEWS.d/next/Library/2018-06-28-13-00-12.bpo-27500._s1gZ5.rst
0 → 100644
View file @
d904c238
Fix getaddrinfo to resolve IPv6 addresses correctly.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment