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
ccfb0fe8
Commit
ccfb0fe8
authored
Oct 07, 2009
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gevent.socket: rename internal helpers wait_reader/wait_writer to wait_read/wait_write
parent
8d3bc8d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
26 deletions
+26
-26
gevent/socket.py
gevent/socket.py
+22
-22
greentest/test__api.py
greentest/test__api.py
+4
-4
No files found.
gevent/socket.py
View file @
ccfb0fe8
...
...
@@ -54,20 +54,20 @@ def _wait_helper(ev, evtype):
current
.
switch
(
ev
)
def
wait_read
er
(
fileno
,
timeout
=-
1
,
timeout_exc
=
_socket
.
timeout
):
def
wait_read
(
fileno
,
timeout
=-
1
,
timeout_exc
=
_socket
.
timeout
):
evt
=
core
.
read_event
(
fileno
,
_wait_helper
,
timeout
,
(
getcurrent
(),
timeout_exc
))
try
:
switch_result
=
get_hub
().
switch
()
assert
evt
is
switch_result
,
'Invalid switch into wait_read
er
(): %r'
%
(
switch_result
,
)
assert
evt
is
switch_result
,
'Invalid switch into wait_read(): %r'
%
(
switch_result
,
)
finally
:
evt
.
cancel
()
def
wait_write
r
(
fileno
,
timeout
=-
1
,
timeout_exc
=
_socket
.
timeout
):
def
wait_write
(
fileno
,
timeout
=-
1
,
timeout_exc
=
_socket
.
timeout
):
evt
=
core
.
write_event
(
fileno
,
_wait_helper
,
timeout
,
(
getcurrent
(),
timeout_exc
))
try
:
switch_result
=
get_hub
().
switch
()
assert
evt
is
switch_result
,
'Invalid switch into wait_write
r
(): %r'
%
(
switch_result
,
)
assert
evt
is
switch_result
,
'Invalid switch into wait_write(): %r'
%
(
switch_result
,
)
finally
:
evt
.
cancel
()
...
...
@@ -204,7 +204,7 @@ class GreenSocket(object):
if
res
is
not
None
:
client
,
addr
=
res
return
type
(
self
)(
client
),
addr
wait_read
er
(
fd
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
fd
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
def
close
(
self
):
self
.
fd
=
_closedsocket
()
...
...
@@ -220,7 +220,7 @@ class GreenSocket(object):
fd
=
self
.
fd
if
self
.
timeout
is
None
:
while
not
socket_connect
(
fd
,
address
):
wait_write
r
(
fd
.
fileno
(),
timeout_exc
=
timeout
)
wait_write
(
fd
.
fileno
(),
timeout_exc
=
timeout
)
else
:
end
=
time
.
time
()
+
self
.
timeout
while
True
:
...
...
@@ -228,7 +228,7 @@ class GreenSocket(object):
return
if
time
.
time
()
>=
end
:
raise
timeout
wait_write
r
(
fd
.
fileno
(),
timeout
=
end
-
time
.
time
(),
timeout_exc
=
timeout
)
wait_write
(
fd
.
fileno
(),
timeout
=
end
-
time
.
time
(),
timeout_exc
=
timeout
)
def
connect_ex
(
self
,
address
):
if
self
.
timeout
==
0.0
:
...
...
@@ -237,7 +237,7 @@ class GreenSocket(object):
if
self
.
timeout
is
None
:
while
not
socket_connect
(
fd
,
address
):
try
:
wait_write
r
(
fd
.
fileno
(),
timeout_exc
=
timeout
)
wait_write
(
fd
.
fileno
(),
timeout_exc
=
timeout
)
except
error
,
ex
:
return
ex
[
0
]
else
:
...
...
@@ -248,7 +248,7 @@ class GreenSocket(object):
if
time
.
time
()
>=
end
:
raise
timeout
try
:
wait_write
r
(
fd
.
fileno
(),
timeout
=
end
-
time
.
time
(),
timeout_exc
=
timeout
)
wait_write
(
fd
.
fileno
(),
timeout
=
end
-
time
.
time
(),
timeout_exc
=
timeout
)
except
error
,
ex
:
return
ex
[
0
]
...
...
@@ -263,30 +263,30 @@ class GreenSocket(object):
def
recv
(
self
,
*
args
):
if
self
.
timeout
!=
0.0
:
wait_read
er
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
res
=
self
.
fd
.
recv
(
*
args
)
return
res
def
recvfrom
(
self
,
*
args
):
if
self
.
timeout
!=
0.0
:
wait_read
er
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
return
self
.
fd
.
recvfrom
(
*
args
)
def
recvfrom_into
(
self
,
*
args
):
if
self
.
timeout
!=
0.0
:
wait_read
er
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
return
self
.
fd
.
recvfrom_into
(
*
args
)
def
recv_into
(
self
,
*
args
):
if
self
.
timeout
!=
0.0
:
wait_read
er
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
return
self
.
fd
.
recv_into
(
*
args
)
def
send
(
self
,
data
,
timeout
=
timeout_default
):
if
timeout
is
timeout_default
:
timeout
=
self
.
timeout
if
timeout
!=
0.0
:
wait_write
r
(
self
.
fileno
(),
timeout
=
timeout
,
timeout_exc
=
_socket
.
timeout
)
wait_write
(
self
.
fileno
(),
timeout
=
timeout
,
timeout_exc
=
_socket
.
timeout
)
return
self
.
fd
.
send
(
data
)
def
sendall
(
self
,
data
):
...
...
@@ -308,7 +308,7 @@ class GreenSocket(object):
def
sendto
(
self
,
*
args
):
if
self
.
timeout
!=
0.0
:
wait_write
r
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_write
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
return
self
.
fd
.
sendto
(
*
args
)
def
setblocking
(
self
,
flag
):
...
...
@@ -372,7 +372,7 @@ class GreenSSL(GreenSocket):
accepted
=
type
(
self
)(
client
,
server_side
=
True
)
accepted
.
do_handshake
()
return
accepted
,
addr
wait_read
er
(
fd
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
fd
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
def
do_handshake
(
self
):
while
True
:
...
...
@@ -380,9 +380,9 @@ class GreenSSL(GreenSocket):
self
.
fd
.
do_handshake
()
break
except
SSL
.
WantReadError
:
wait_read
er
(
self
.
fileno
())
wait_read
(
self
.
fileno
())
except
SSL
.
WantWriteError
:
wait_write
r
(
self
.
fileno
())
wait_write
(
self
.
fileno
())
except
SSL
.
SysCallError
,
ex
:
raise
sslerror
(
SysCallError_code_mapping
.
get
(
ex
.
args
[
0
],
ex
.
args
[
0
]),
ex
.
args
[
1
])
except
SSL
.
Error
,
ex
:
...
...
@@ -402,12 +402,12 @@ class GreenSSL(GreenSocket):
if
self
.
timeout
==
0.0
:
raise
timeout
(
str
(
ex
))
else
:
wait_write
r
(
self
.
fileno
(),
timeout
=
timeout
,
timeout_exc
=
_socket
.
timeout
)
wait_write
(
self
.
fileno
(),
timeout
=
timeout
,
timeout_exc
=
_socket
.
timeout
)
except
SSL
.
WantReadError
,
ex
:
if
self
.
timeout
==
0.0
:
raise
timeout
(
str
(
ex
))
else
:
wait_read
er
(
self
.
fileno
(),
timeout
=
timeout
,
timeout_exc
=
_socket
.
timeout
)
wait_read
(
self
.
fileno
(),
timeout
=
timeout
,
timeout_exc
=
_socket
.
timeout
)
except
SSL
.
SysCallError
,
e
:
if
e
[
0
]
==
-
1
and
data
==
""
:
# errors when writing empty strings are expected and can be ignored
...
...
@@ -427,12 +427,12 @@ class GreenSSL(GreenSocket):
if
self
.
timeout
==
0.0
:
raise
timeout
(
str
(
ex
))
else
:
wait_read
er
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
except
SSL
.
WantWriteError
,
ex
:
if
self
.
timeout
==
0.0
:
raise
timeout
(
str
(
ex
))
else
:
wait_read
er
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
wait_read
(
self
.
fileno
(),
timeout
=
self
.
timeout
,
timeout_exc
=
timeout
)
except
SSL
.
ZeroReturnError
:
return
''
except
SSL
.
SysCallError
,
ex
:
...
...
greentest/test__api.py
View file @
ccfb0fe8
...
...
@@ -69,15 +69,15 @@ class Test(greentest.TestCase):
assert
isinstance
(
result
,
AssertionError
),
result
assert
'Invalid switch'
in
str
(
result
),
repr
(
str
(
result
))
def
test_wait_read
er
_invalid_switch
(
self
):
p
=
gevent
.
spawn
(
util
.
wrap_errors
(
AssertionError
,
socket
.
wait_read
er
),
0
)
def
test_wait_read_invalid_switch
(
self
):
p
=
gevent
.
spawn
(
util
.
wrap_errors
(
AssertionError
,
socket
.
wait_read
),
0
)
gevent
.
spawn
(
p
.
switch
,
None
)
result
=
p
.
get
()
assert
isinstance
(
result
,
AssertionError
),
result
assert
'Invalid switch'
in
str
(
result
),
repr
(
str
(
result
))
def
test_wait_write
r
_invalid_switch
(
self
):
p
=
gevent
.
spawn
(
util
.
wrap_errors
(
AssertionError
,
socket
.
wait_write
r
),
0
)
def
test_wait_write_invalid_switch
(
self
):
p
=
gevent
.
spawn
(
util
.
wrap_errors
(
AssertionError
,
socket
.
wait_write
),
0
)
gevent
.
spawn
(
p
.
switch
,
None
)
result
=
p
.
get
()
assert
isinstance
(
result
,
AssertionError
),
result
...
...
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