Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
c9539335
Commit
c9539335
authored
Jun 29, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pr399'
parents
dafe42a2
23683507
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
gevent/_socket3.py
gevent/_socket3.py
+24
-3
greentest/test__socket.py
greentest/test__socket.py
+5
-0
No files found.
gevent/_socket3.py
View file @
c9539335
# Port of Python 3.3's socket module to gevent
import
io
import
sys
import
time
from
gevent
import
_socketcommon
import
_socket
...
...
@@ -65,7 +66,11 @@ class socket(object):
# Only defined under Linux
@
property
def
type
(
self
):
return
self
.
_sock
.
type
&
~
_socket
.
SOCK_NONBLOCK
# See https://github.com/gevent/gevent/pull/399
if
self
.
timeout
!=
0.0
:
return
self
.
_sock
.
type
&
~
_socket
.
SOCK_NONBLOCK
else
:
return
self
.
_sock
.
type
def
__enter__
(
self
):
return
self
...
...
@@ -375,8 +380,24 @@ class socket(object):
self
.
hub
.
cancel_wait
(
self
.
_write_event
,
cancel_wait_ex
)
self
.
_sock
.
shutdown
(
how
)
SocketType
=
socket
if
sys
.
version_info
[:
2
]
==
(
3
,
4
)
and
sys
.
version_info
[:
3
]
<=
(
3
,
4
,
2
):
# Python 3.4, up to and including 3.4.2, had a bug where the
# SocketType enumeration overwrote the SocketType class imported
# from _socket. This was fixed in 3.4.3 (http://bugs.python.org/issue20386
# and https://github.com/python/cpython/commit/0d2f85f38a9691efdfd1e7285c4262cab7f17db7).
# Prior to that, if we replace SocketType with our own class, the implementation
# of socket.type breaks with "OSError: [Errno 97] Address family not supported by protocol".
# Therefore, on these old versions, we must preserve it as an enum; while this
# seems like it could lead to non-green behaviour, code on those versions
# cannot possibly be using SocketType as a class anyway.
SocketType
=
__socket__
.
SocketType
# Fixup __all__; note that we get exec'd multiple times during unit tests
if
'SocketType'
in
__implements__
:
__implements__
.
remove
(
'SocketType'
)
if
'SocketType'
not
in
__imports__
:
__imports__
.
append
(
'SocketType'
)
else
:
SocketType
=
socket
def
fromfd
(
fd
,
family
,
type
,
proto
=
0
):
...
...
greentest/test__socket.py
View file @
c9539335
...
...
@@ -195,6 +195,11 @@ class TestTCP(greentest.TestCase):
s
.
settimeout
(
1
)
self
.
assertEqual
(
socket
.
AF_INET
,
s
.
type
)
s
.
setblocking
(
0
)
std_socket
=
monkey
.
get_original
(
'socket'
,
'socket'
)(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
,
0
)
std_socket
.
setblocking
(
0
)
self
.
assertEqual
(
std_socket
.
type
,
s
.
type
)
def
get_port
():
tempsock
=
socket
.
socket
()
...
...
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