Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
coco
Commits
ba26608a
Commit
ba26608a
authored
Oct 21, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change select to selector
parent
f2f280ff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
session.py
coco/session.py
+11
-3
No files found.
coco/session.py
View file @
ba26608a
...
...
@@ -5,6 +5,8 @@ import uuid
import
socket
import
logging
import
datetime
import
selectors
BUF_SIZE
=
1024
logger
=
logging
.
getLogger
(
__file__
)
...
...
@@ -21,6 +23,7 @@ class Session:
self
.
running
=
True
self
.
date_created
=
datetime
.
datetime
.
now
()
self
.
date_finished
=
None
self
.
sel
=
selectors
.
DefaultSelector
()
def
add_watcher
(
self
,
watcher
):
"""
...
...
@@ -31,11 +34,13 @@ class Session:
"""
logger
.
info
(
"Session
%
add watcher
%
s"
%
(
self
,
watcher
))
watcher
.
send
(
"Welcome to join session
%
s
\r\n
"
%
self
.
id
)
self
.
sel
.
register
(
watcher
,
selectors
.
EVENT_READ
)
self
.
watchers
.
append
(
watcher
)
def
remove_watcher
(
self
,
watcher
):
logger
.
info
(
"Session
%
s remove watcher
%
s"
%
(
self
,
watcher
))
watcher
.
send
(
"Leave session
%
s at
%
s"
%
(
self
.
id
,
datetime
.
datetime
.
now
()))
self
.
sel
.
unregister
(
watcher
)
self
.
watchers
.
remove
(
watcher
)
def
add_sharer
(
self
,
sharer
):
...
...
@@ -46,11 +51,13 @@ class Session:
"""
logger
.
info
(
"Session
%
s add share
%
s"
%
(
self
.
id
,
sharer
))
sharer
.
send
(
"Welcome to join session
%
s
\r\n
"
%
self
.
id
)
self
.
sel
.
register
(
sharer
,
selectors
.
EVENT_READ
)
self
.
sharers
.
append
(
sharer
)
def
remove_sharer
(
self
,
sharer
):
logger
.
info
(
"Session
%
s remove sharer
%
s"
%
(
self
.
id
,
sharer
))
sharer
.
send
(
"Leave session
%
s at
%
s"
%
(
self
.
id
,
datetime
.
datetime
.
now
()))
self
.
sel
.
unregister
(
sharer
)
self
.
sharers
.
remove
(
sharer
)
def
bridge
(
self
):
...
...
@@ -60,10 +67,11 @@ class Session:
"""
logger
.
info
(
"Start bridge session
%
s"
%
self
.
id
)
self
.
sel
.
register
(
self
.
client
,
selectors
.
EVENT_READ
)
self
.
sel
.
register
(
self
.
server
,
selectors
.
EVENT_READ
)
while
self
.
running
:
r
,
w
,
x
=
select
.
select
([
self
.
client
,
self
.
server
]
+
self
.
watchers
+
self
.
sharers
,
[],
[])
for
sock
in
r
:
events
=
self
.
sel
.
select
()
for
sock
in
[
key
.
fileobj
for
key
,
_
in
events
]:
data
=
sock
.
recv
(
BUF_SIZE
)
if
sock
==
self
.
server
:
if
len
(
data
)
==
0
:
...
...
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