Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wspy
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
wspy
Commits
5af22f06
Commit
5af22f06
authored
Dec 17, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debugged AsyncServer
parent
553aa17f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
25 deletions
+35
-25
async.py
async.py
+18
-13
server.py
server.py
+17
-11
websocket.py
websocket.py
+0
-1
No files found.
async.py
View file @
5af22f06
...
...
@@ -33,7 +33,7 @@ class AsyncConnection(Connection):
'instead'
%
frame
)
def
send
(
self
,
message
,
fragment_size
=
None
,
mask
=
False
):
frames
=
self
.
message_to_frames
(
message
,
fragment_size
,
mask
)
frames
=
list
(
self
.
message_to_frames
(
message
,
fragment_size
,
mask
)
)
for
frame
in
frames
[:
-
1
]:
self
.
sock
.
queue_send
(
frame
)
...
...
@@ -98,7 +98,7 @@ class AsyncServer(Server):
@
property
def
clients
(
self
):
return
self
.
conns
.
iter
values
()
return
self
.
conns
.
values
()
def
remove_client
(
self
,
client
,
code
,
reason
):
self
.
epoll
.
unregister
(
client
.
fno
)
...
...
@@ -138,18 +138,10 @@ class AsyncServer(Server):
except
SocketClosed
:
continue
except
Exception
as
e
:
logging
.
error
(
format_exc
(
e
))
logging
.
error
(
format_exc
(
e
)
.
rstrip
()
)
continue
mask
=
0
if
conn
.
sock
.
can_send
():
mask
|=
EPOLLOUT
if
conn
.
sock
.
can_recv
():
mask
|=
EPOLLIN
self
.
epoll
.
modify
(
fileno
,
mask
)
self
.
update_mask
(
conn
)
def
run
(
self
):
try
:
...
...
@@ -162,8 +154,19 @@ class AsyncServer(Server):
self
.
epoll
.
close
()
self
.
sock
.
close
()
def
update_mask
(
self
,
conn
):
mask
=
0
if
conn
.
sock
.
can_send
():
mask
|=
EPOLLOUT
if
conn
.
sock
.
can_recv
():
mask
|=
EPOLLIN
self
.
epoll
.
modify
(
conn
.
sock
.
fileno
(),
mask
)
def
onsend
(
self
,
client
,
message
):
logging
.
debug
(
'Written "%s" to %s'
,
message
,
client
)
return
NotImplemented
class
AsyncClient
(
Client
,
AsyncConnection
):
...
...
@@ -174,8 +177,10 @@ class AsyncClient(Client, AsyncConnection):
def
send
(
self
,
message
,
fragment_size
=
None
,
mask
=
False
):
logging
.
debug
(
'Enqueueing %s to %s'
,
message
,
self
)
AsyncConnection
.
send
(
self
,
message
,
fragment_size
,
mask
)
self
.
server
.
update_mask
(
self
)
def
onsend
(
self
,
message
):
logging
.
debug
(
'Finished sending %s to %s'
,
message
,
self
)
self
.
server
.
onsend
(
self
,
message
)
...
...
server.py
View file @
5af22f06
...
...
@@ -136,27 +136,22 @@ class Server(object):
self
.
onclose
(
client
,
code
,
reason
)
def
onopen
(
self
,
client
):
logging
.
debug
(
'Opened socket to %s'
,
client
)
return
NotImplemented
def
onmessage
(
self
,
client
,
message
):
logging
.
debug
(
'Received %s from %s'
,
message
,
client
)
return
NotImplemented
def
onping
(
self
,
client
,
payload
):
logging
.
debug
(
'Sent ping "%s" to %s'
,
payload
,
client
)
return
NotImplemented
def
onpong
(
self
,
client
,
payload
):
logging
.
debug
(
'Received pong "%s" from %s'
,
payload
,
client
)
return
NotImplemented
def
onclose
(
self
,
client
,
code
,
reason
):
msg
=
'Closed socket to %s'
%
client
if
code
is
not
None
:
msg
+=
': [%d] %s'
%
(
code
,
reason
)
logging
.
debug
(
msg
)
return
NotImplemented
def
onerror
(
self
,
client
,
e
):
logging
.
error
(
format_exc
(
e
))
return
NotImplemented
class
Client
(
Connection
):
...
...
@@ -175,21 +170,32 @@ class Client(Connection):
Connection
.
send
(
self
,
message
,
fragment_size
=
fragment_size
,
mask
=
mask
)
def
onopen
(
self
):
logging
.
debug
(
'Opened socket to %s'
,
self
)
self
.
server
.
onopen
(
self
)
def
onmessage
(
self
,
message
):
logging
.
debug
(
'Received %s from %s'
,
message
,
self
)
self
.
server
.
onmessage
(
self
,
message
)
def
onping
(
self
,
payload
):
logging
.
debug
(
'Sent ping "%s" to %s'
,
payload
,
self
)
self
.
server
.
onping
(
self
,
payload
)
def
onpong
(
self
,
payload
):
logging
.
debug
(
'Received pong "%s" from %s'
,
payload
,
self
)
self
.
server
.
onpong
(
self
,
payload
)
def
onclose
(
self
,
code
,
reason
):
msg
=
'Closed socket to %s'
%
self
if
code
is
not
None
:
msg
+=
': [%d] %s'
%
(
code
,
reason
)
logging
.
debug
(
msg
)
self
.
server
.
remove_client
(
self
,
code
,
reason
)
def
onerror
(
self
,
e
):
logging
.
error
(
format_exc
(
e
))
self
.
server
.
onerror
(
self
,
e
)
...
...
websocket.py
View file @
5af22f06
...
...
@@ -195,7 +195,6 @@ class websocket(object):
nframes
+=
1
if
callback
:
print
'write cb'
callback
()
else
:
entry
[
1
]
-=
nwritten
...
...
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