Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
90cbb552
Commit
90cbb552
authored
10 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
changed from select to poll
parent
5a94b933
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
channels/sockets/sockets.py
+50
-36
50 additions, 36 deletions
channels/sockets/sockets.py
with
50 additions
and
36 deletions
channels/sockets/sockets.py
+
50
−
36
View file @
90cbb552
...
...
@@ -267,11 +267,17 @@ class ServerSocket(FileDescriptorChannel):
def
fileno
(
self
):
return
self
.
socket
.
fileno
()
_BASELEVEL
=
select
.
POLLIN
|
select
.
POLLOUT
|
select
.
POLLERR
|
select
.
POLLHUP
|
select
.
POLLNVAL
class
SelectHandlingLayer
(
HandlingLayer
):
"""
A select-based handling layer
"""
def
__init__
(
self
):
HandlingLayer
.
__init__
(
self
)
self
.
poll
=
select
.
poll
()
self
.
fdmap
=
{}
def
register_channel
(
self
,
channel
):
"""
...
...
@@ -288,6 +294,9 @@ class SelectHandlingLayer(HandlingLayer):
raise
ValueError
,
'
is_write_pending() method lacking
'
self
.
channels
.
append
(
channel
)
self
.
poll
.
register
(
channel
,
select
.
POLLIN
|
select
.
POLLERR
|
select
.
POLLHUP
|
select
.
POLLNVAL
)
self
.
fdmap
[
channel
.
fileno
()]
=
channel
def
unregister_channel
(
self
,
channel
):
"""
...
...
@@ -298,7 +307,9 @@ class SelectHandlingLayer(HandlingLayer):
"""
try
:
self
.
channels
.
remove
(
channel
)
except
ValueError
:
self
.
poll
.
unregister
(
channel
)
del
self
.
fdmap
[
channel
.
fileno
()]
except
(
ValueError
,
KeyError
,
select
.
error
):
raise
ValueError
,
'
channel not found
'
def
close_channel
(
self
,
channel
):
...
...
@@ -306,47 +317,50 @@ class SelectHandlingLayer(HandlingLayer):
Channel unregister + channel close
"""
self
.
unregister_channel
(
channel
)
try
:
self
.
poll
.
unregister
(
channel
)
del
self
.
fdmap
[
channel
.
fileno
()]
except
KeyError
:
pass
channel
.
on_closed
()
# this should close the channel
self
.
on_closed
(
channel
)
def
select
(
self
,
timeout
=
5
):
self
.
on_iteration
()
writables
=
[
x
for
x
in
self
.
channels
if
x
.
is_write_pending
()]
try
:
rs
,
ws
,
xs
=
select
.
select
(
self
.
channels
,
writables
,
(),
timeout
)
except
select
.
error
:
# we need to trace over each channel to determine who has failed
for
channel
in
self
.
channels
:
for
x
in
self
.
channels
:
if
x
.
is_write_pending
():
self
.
poll
.
modify
(
x
,
_BASELEVEL
|
select
.
POLLOUT
)
else
:
self
.
poll
.
modify
(
x
,
_BASELEVEL
)
events
=
self
.
poll
.
poll
(
timeout
)
# Now, for each event...
for
fdinfo
,
event
in
events
:
channel
=
self
.
fdmap
[
fdinfo
]
if
event
&
(
select
.
EPOLLHUP
|
select
.
POLLERR
|
select
.
POLLNVAL
):
self
.
close_channel
(
channel
)
return
if
event
&
select
.
POLLIN
:
try
:
select
.
select
((
channel
,
),
(),
(),
0
)
except
select
.
error
:
# we found the one
channel
.
on_readable
()
except
(
ChannelFailure
,
ChannelClosed
):
self
.
close_channel
(
channel
)
return
except
socket
.
error
:
raise
RuntimeError
,
'
ABEND: socket error in select loop
'
# Now, for each writeable channel...
for
writable
in
ws
:
try
:
if
not
writable
.
connected
:
writable
.
on_writable
()
self
.
on_connected
(
writable
)
else
:
writable
.
on_writable
()
except
ChannelFailure
:
self
.
close_channel
(
writable
)
return
self
.
on_writable
(
writable
)
# For each readable channel...
for
readable
in
rs
:
try
:
readable
.
on_readable
()
except
(
ChannelFailure
,
ChannelClosed
):
self
.
close_channel
(
readable
)
return
self
.
on_readable
(
readable
)
self
.
on_readable
(
channel
)
if
event
&
select
.
POLLOUT
:
try
:
if
not
channel
.
connected
:
channel
.
on_writable
()
self
.
on_connected
(
channel
)
else
:
channel
.
on_writable
()
except
ChannelFailure
:
self
.
close_channel
(
channel
)
return
self
.
on_writable
(
channel
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment