Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
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
郑天保
webssh
Commits
b88a159f
Commit
b88a159f
authored
Apr 14, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a parameter for worker to close with a reason
parent
e8924f1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
12 deletions
+16
-12
handler.py
handler.py
+5
-3
worker.py
worker.py
+11
-9
No files found.
handler.py
View file @
b88a159f
...
...
@@ -126,7 +126,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
except
socket
.
error
:
raise
ValueError
(
'Unable to connect to {}:{}'
.
format
(
*
dst_addr
))
except
paramiko
.
BadAuthenticationType
:
raise
ValueError
(
'
A
uthentication failed.'
)
raise
ValueError
(
'
SSH a
uthentication failed.'
)
except
paramiko
.
BadHostKeyException
:
raise
ValueError
(
'Bad host key.'
)
...
...
@@ -190,7 +190,7 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
self
.
worker_ref
=
weakref
.
ref
(
worker
)
self
.
loop
.
add_handler
(
worker
.
fd
,
worker
,
IOLoop
.
READ
)
else
:
self
.
close
()
self
.
close
(
reason
=
'Websocket authentication failed.'
)
def
on_message
(
self
,
message
):
logging
.
debug
(
'{!r} from {}:{}'
.
format
(
message
,
*
self
.
src_addr
))
...
...
@@ -202,4 +202,6 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
logging
.
info
(
'Disconnected from {}:{}'
.
format
(
*
self
.
src_addr
))
worker
=
self
.
worker_ref
()
if
self
.
worker_ref
else
None
if
worker
:
worker
.
close
()
if
self
.
close_reason
is
None
:
self
.
close_reason
=
'client disconnected'
worker
.
close
(
reason
=
self
.
close_reason
)
worker.py
View file @
b88a159f
...
...
@@ -13,9 +13,9 @@ workers = {}
def
recycle_worker
(
worker
):
if
worker
.
handler
:
return
logging
.
debug
(
'Recycling worker {}'
.
format
(
worker
.
id
))
logging
.
warn
(
'Recycling worker {}'
.
format
(
worker
.
id
))
workers
.
pop
(
worker
.
id
,
None
)
worker
.
close
()
worker
.
close
(
reason
=
'worker recycled'
)
class
Worker
(
object
):
...
...
@@ -36,7 +36,7 @@ class Worker(object):
if
events
&
IOLoop
.
WRITE
:
self
.
on_write
()
if
events
&
IOLoop
.
ERROR
:
self
.
close
()
self
.
close
(
reason
=
'error event occurred'
)
def
set_handler
(
self
,
handler
):
if
not
self
.
handler
:
...
...
@@ -54,18 +54,18 @@ class Worker(object):
except
(
OSError
,
IOError
)
as
e
:
logging
.
error
(
e
)
if
errno_from_exception
(
e
)
in
_ERRNO_CONNRESET
:
self
.
close
()
self
.
close
(
reason
=
'chan error on reading'
)
else
:
logging
.
debug
(
'{!r} from {}:{}'
.
format
(
data
,
*
self
.
dst_addr
))
if
not
data
:
self
.
close
()
self
.
close
(
reason
=
'chan closed'
)
return
logging
.
debug
(
'{!r} to {}:{}'
.
format
(
data
,
*
self
.
handler
.
src_addr
))
try
:
self
.
handler
.
write_message
(
data
)
except
tornado
.
websocket
.
WebSocketClosedError
:
self
.
close
()
self
.
close
(
reason
=
'websocket closed'
)
def
on_write
(
self
):
logging
.
debug
(
'worker {} on write'
.
format
(
self
.
id
))
...
...
@@ -80,7 +80,7 @@ class Worker(object):
except
(
OSError
,
IOError
)
as
e
:
logging
.
error
(
e
)
if
errno_from_exception
(
e
)
in
_ERRNO_CONNRESET
:
self
.
close
()
self
.
close
(
reason
=
'chan error on writing'
)
else
:
self
.
update_handler
(
IOLoop
.
WRITE
)
else
:
...
...
@@ -92,8 +92,10 @@ class Worker(object):
else
:
self
.
update_handler
(
IOLoop
.
READ
)
def
close
(
self
):
logging
.
debug
(
'Closing worker {}'
.
format
(
self
.
id
))
def
close
(
self
,
reason
=
None
):
logging
.
info
(
'Closing worker {} with reason {}'
.
format
(
self
.
id
,
reason
)
)
if
self
.
handler
:
self
.
loop
.
remove_handler
(
self
.
fd
)
self
.
handler
.
close
()
...
...
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