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
08af39dc
Commit
08af39dc
authored
Nov 11, 2017
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handled ERRNO_CONNRESET
parent
f9a66a9e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
14 deletions
+26
-14
main.py
main.py
+26
-14
No files found.
main.py
View file @
08af39dc
import
io
import
io
import
logging
import
logging
import
os.path
import
os.path
import
socket
import
traceback
import
traceback
import
uuid
import
uuid
import
weakref
import
weakref
...
@@ -9,7 +8,9 @@ import paramiko
...
@@ -9,7 +8,9 @@ import paramiko
import
tornado.web
import
tornado.web
import
tornado.websocket
import
tornado.websocket
from
tornado.ioloop
import
IOLoop
from
tornado.ioloop
import
IOLoop
from
tornado.iostream
import
_ERRNO_CONNRESET
from
tornado.options
import
define
,
options
,
parse_command_line
from
tornado.options
import
define
,
options
,
parse_command_line
from
tornado.util
import
errno_from_exception
define
(
'address'
,
default
=
'127.0.0.1'
,
help
=
'listen address'
)
define
(
'address'
,
default
=
'127.0.0.1'
,
help
=
'listen address'
)
...
@@ -56,31 +57,42 @@ class Worker(object):
...
@@ -56,31 +57,42 @@ class Worker(object):
def
on_read
(
self
):
def
on_read
(
self
):
logging
.
debug
(
'worker {} on read'
.
format
(
self
.
id
))
logging
.
debug
(
'worker {} on read'
.
format
(
self
.
id
))
data
=
self
.
chan
.
recv
(
BUF_SIZE
)
logging
.
debug
(
'"{}" from {}'
.
format
(
data
,
self
.
dst_addr
))
if
not
data
:
self
.
close
()
return
logging
.
debug
(
'"{}" to {}'
.
format
(
data
,
self
.
handler
.
src_addr
))
try
:
try
:
self
.
handler
.
write_message
(
data
)
data
=
self
.
chan
.
recv
(
BUF_SIZE
)
except
tornado
.
websocket
.
WebSocketClosedError
:
except
(
OSError
,
IOError
)
as
e
:
self
.
close
()
logging
.
error
(
e
)
if
errno_from_exception
(
e
)
in
_ERRNO_CONNRESET
:
self
.
close
()
else
:
logging
.
debug
(
'"{}" from {}'
.
format
(
data
,
self
.
dst_addr
))
if
not
data
:
self
.
close
()
return
logging
.
debug
(
'"{}" to {}'
.
format
(
data
,
self
.
handler
.
src_addr
))
try
:
self
.
handler
.
write_message
(
data
)
except
tornado
.
websocket
.
WebSocketClosedError
:
self
.
close
()
def
on_write
(
self
):
def
on_write
(
self
):
logging
.
debug
(
'worker {} on write'
.
format
(
self
.
id
))
logging
.
debug
(
'worker {} on write'
.
format
(
self
.
id
))
if
not
self
.
data_to_dst
:
if
not
self
.
data_to_dst
:
return
return
data
=
''
.
join
(
self
.
data_to_dst
)
data
=
''
.
join
(
self
.
data_to_dst
)
self
.
data_to_dst
=
[]
logging
.
debug
(
'"{}" to {}'
.
format
(
data
,
self
.
dst_addr
))
logging
.
debug
(
'"{}" to {}'
.
format
(
data
,
self
.
dst_addr
))
try
:
try
:
sent
=
self
.
chan
.
send
(
data
)
sent
=
self
.
chan
.
send
(
data
)
except
socket
.
error
as
e
:
except
(
OSError
,
IOError
)
as
e
:
logging
.
error
(
e
)
logging
.
error
(
e
)
self
.
close
()
if
errno_from_exception
(
e
)
in
_ERRNO_CONNRESET
:
self
.
close
()
else
:
self
.
loop
.
update_handler
(
self
.
fd
,
IOLoop
.
WRITE
)
else
:
else
:
self
.
data_to_dst
=
[]
data
=
data
[
sent
:]
data
=
data
[
sent
:]
if
data
:
if
data
:
self
.
data_to_dst
.
append
(
data
)
self
.
data_to_dst
.
append
(
data
)
...
...
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