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
c7dc55eb
Commit
c7dc55eb
authored
Oct 14, 2014
by
Victor Stinner
Browse files
Options
Browse Files
Download
Plain Diff
Merge 3.4 (asyncio)
parents
0eb1896a
f67f4602
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
41 deletions
+47
-41
Lib/asyncio/windows_utils.py
Lib/asyncio/windows_utils.py
+43
-41
Lib/test/test_asyncio/test_windows_utils.py
Lib/test/test_asyncio/test_windows_utils.py
+4
-0
No files found.
Lib/asyncio/windows_utils.py
View file @
c7dc55eb
...
@@ -28,49 +28,51 @@ STDOUT = subprocess.STDOUT
...
@@ -28,49 +28,51 @@ STDOUT = subprocess.STDOUT
_mmap_counter
=
itertools
.
count
()
_mmap_counter
=
itertools
.
count
()
# Replacement for socket.socketpair()
if
hasattr
(
socket
,
'socketpair'
):
# Since Python 3.5, socket.socketpair() is now also available on Windows
socketpair
=
socket
.
socketpair
def
socketpair
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
0
):
else
:
"""A socket pair usable as a self-pipe, for Windows.
# Replacement for socket.socketpair()
def
socketpair
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
0
):
Origin: https://gist.github.com/4325783, by Geert Jansen. Public domain.
"""A socket pair usable as a self-pipe, for Windows.
"""
if
family
==
socket
.
AF_INET
:
Origin: https://gist.github.com/4325783, by Geert Jansen. Public domain.
host
=
'127.0.0.1'
"""
elif
family
==
socket
.
AF_INET6
:
if
family
==
socket
.
AF_INET
:
host
=
'::1'
host
=
'127.0.0.1'
else
:
elif
family
==
socket
.
AF_INET6
:
raise
ValueError
(
"Ony AF_INET and AF_INET6 socket address families "
host
=
'::1'
"are supported"
)
else
:
if
type
!=
socket
.
SOCK_STREAM
:
raise
ValueError
(
"Only AF_INET and AF_INET6 socket address families "
raise
ValueError
(
"Only SOCK_STREAM socket type is supported"
)
"are supported"
)
if
proto
!=
0
:
if
type
!=
socket
.
SOCK_STREAM
:
raise
ValueError
(
"Only protocol zero is supported"
)
raise
ValueError
(
"Only SOCK_STREAM socket type is supported"
)
if
proto
!=
0
:
# We create a connected TCP socket. Note the trick with setblocking(0)
raise
ValueError
(
"Only protocol zero is supported"
)
# that prevents us from having to create a thread.
lsock
=
socket
.
socket
(
family
,
type
,
proto
)
# We create a connected TCP socket. Note the trick with setblocking(0)
try
:
# that prevents us from having to create a thread.
lsock
.
bind
((
host
,
0
))
lsock
=
socket
.
socket
(
family
,
type
,
proto
)
lsock
.
listen
(
1
)
# On IPv6, ignore flow_info and scope_id
addr
,
port
=
lsock
.
getsockname
()[:
2
]
csock
=
socket
.
socket
(
family
,
type
,
proto
)
try
:
try
:
csock
.
setblocking
(
False
)
lsock
.
bind
((
host
,
0
))
lsock
.
listen
(
1
)
# On IPv6, ignore flow_info and scope_id
addr
,
port
=
lsock
.
getsockname
()[:
2
]
csock
=
socket
.
socket
(
family
,
type
,
proto
)
try
:
try
:
csock
.
connect
((
addr
,
port
))
csock
.
setblocking
(
False
)
except
(
BlockingIOError
,
InterruptedError
):
try
:
pass
csock
.
connect
((
addr
,
port
))
ssock
,
_
=
lsock
.
accept
()
except
(
BlockingIOError
,
InterruptedError
):
csock
.
setblocking
(
True
)
pass
except
:
csock
.
setblocking
(
True
)
csock
.
close
()
ssock
,
_
=
lsock
.
accept
()
raise
except
:
finally
:
csock
.
close
()
lsock
.
close
()
raise
return
(
ssock
,
csock
)
finally
:
lsock
.
close
()
return
(
ssock
,
csock
)
# Replacement for os.pipe() using handles instead of fds
# Replacement for os.pipe() using handles instead of fds
...
...
Lib/test/test_asyncio/test_windows_utils.py
View file @
c7dc55eb
...
@@ -33,6 +33,8 @@ class WinsocketpairTests(unittest.TestCase):
...
@@ -33,6 +33,8 @@ class WinsocketpairTests(unittest.TestCase):
ssock
,
csock
=
windows_utils
.
socketpair
(
family
=
socket
.
AF_INET6
)
ssock
,
csock
=
windows_utils
.
socketpair
(
family
=
socket
.
AF_INET6
)
self
.
check_winsocketpair
(
ssock
,
csock
)
self
.
check_winsocketpair
(
ssock
,
csock
)
@
unittest
.
skipIf
(
hasattr
(
socket
,
'socketpair'
),
'socket.socketpair is available'
)
@
mock
.
patch
(
'asyncio.windows_utils.socket'
)
@
mock
.
patch
(
'asyncio.windows_utils.socket'
)
def
test_winsocketpair_exc
(
self
,
m_socket
):
def
test_winsocketpair_exc
(
self
,
m_socket
):
m_socket
.
AF_INET
=
socket
.
AF_INET
m_socket
.
AF_INET
=
socket
.
AF_INET
...
@@ -51,6 +53,8 @@ class WinsocketpairTests(unittest.TestCase):
...
@@ -51,6 +53,8 @@ class WinsocketpairTests(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
self
.
assertRaises
(
ValueError
,
windows_utils
.
socketpair
,
proto
=
1
)
windows_utils
.
socketpair
,
proto
=
1
)
@
unittest
.
skipIf
(
hasattr
(
socket
,
'socketpair'
),
'socket.socketpair is available'
)
@
mock
.
patch
(
'asyncio.windows_utils.socket'
)
@
mock
.
patch
(
'asyncio.windows_utils.socket'
)
def
test_winsocketpair_close
(
self
,
m_socket
):
def
test_winsocketpair_close
(
self
,
m_socket
):
m_socket
.
AF_INET
=
socket
.
AF_INET
m_socket
.
AF_INET
=
socket
.
AF_INET
...
...
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