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
444ba916
Commit
444ba916
authored
Mar 07, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 性能优化
parent
b0f0453d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
5 deletions
+30
-5
app.py
coco/app.py
+2
-1
char.py
coco/char.py
+2
-0
interactive.py
coco/interactive.py
+2
-1
models.py
coco/models.py
+24
-3
No files found.
coco/app.py
View file @
444ba916
...
@@ -205,6 +205,7 @@ class Coco:
...
@@ -205,6 +205,7 @@ class Coco:
for
client
in
self
.
clients
:
for
client
in
self
.
clients
:
self
.
remove_client
(
client
)
self
.
remove_client
(
client
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
heartbeat
()
self
.
stop_evt
.
set
()
self
.
stop_evt
.
set
()
self
.
sshd
.
shutdown
()
self
.
sshd
.
shutdown
()
self
.
httpd
.
shutdown
()
self
.
httpd
.
shutdown
()
...
@@ -234,4 +235,4 @@ class Coco:
...
@@ -234,4 +235,4 @@ class Coco:
with
self
.
lock
:
with
self
.
lock
:
logger
.
info
(
"Remove session: {}"
.
format
(
session
))
logger
.
info
(
"Remove session: {}"
.
format
(
session
))
self
.
sessions
.
remove
(
session
)
self
.
sessions
.
remove
(
session
)
self
.
service
.
finish_session
(
session
.
id
)
self
.
service
.
finish_session
(
session
.
to_json
()
)
coco/char.py
View file @
444ba916
...
@@ -4,7 +4,9 @@
...
@@ -4,7 +4,9 @@
BACKSPACE_CHAR
=
{
b
'
\x08
'
:
b
'
\x08\x1b
[K'
,
b
'
\x7f
'
:
b
'
\x08\x1b
[K'
}
BACKSPACE_CHAR
=
{
b
'
\x08
'
:
b
'
\x08\x1b
[K'
,
b
'
\x7f
'
:
b
'
\x08\x1b
[K'
}
ENTER_CHAR
=
[
b
'
\r
'
,
b
'
\n
'
,
b
'
\r\n
'
]
ENTER_CHAR
=
[
b
'
\r
'
,
b
'
\n
'
,
b
'
\r\n
'
]
ENTER_CHAR_ORDER
=
[
ord
(
b
'
\r
'
),
ord
(
b
'
\n
'
)]
UNSUPPORTED_CHAR
=
{
b
'
\x15
'
:
'Ctrl-U'
,
b
'
\x0c
'
:
'Ctrl-L'
,
b
'
\x05
'
:
'Ctrl-E'
}
UNSUPPORTED_CHAR
=
{
b
'
\x15
'
:
'Ctrl-U'
,
b
'
\x0c
'
:
'Ctrl-L'
,
b
'
\x05
'
:
'Ctrl-E'
}
CLEAR_CHAR
=
b
'
\x1b
[H
\x1b
[2J'
CLEAR_CHAR
=
b
'
\x1b
[H
\x1b
[2J'
BELL_CHAR
=
b
'
\x07
'
BELL_CHAR
=
b
'
\x07
'
NEW_LINE
=
b
'
\r\n
'
NEW_LINE
=
b
'
\r\n
'
RZ_PROTOCOL_CHAR
=
b
'**
\x18
B0900000000a87c
\r\x8a\x11
'
coco/interactive.py
View file @
444ba916
...
@@ -80,6 +80,7 @@ class InteractiveServer:
...
@@ -80,6 +80,7 @@ class InteractiveServer:
input_data
=
[]
input_data
=
[]
parser
=
TtyIOParser
()
parser
=
TtyIOParser
()
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
while
True
:
while
True
:
data
=
self
.
client
.
recv
(
10
)
data
=
self
.
client
.
recv
(
10
)
logger
.
debug
(
data
)
logger
.
debug
(
data
)
...
@@ -113,7 +114,7 @@ class InteractiveServer:
...
@@ -113,7 +114,7 @@ class InteractiveServer:
# handle shell expect
# handle shell expect
multi_char_with_enter
=
False
multi_char_with_enter
=
False
if
len
(
data
)
>
1
and
data
[
-
1
]
in
char
.
ENTER_CHAR
:
if
len
(
data
)
>
1
and
data
[
-
1
]
in
char
.
ENTER_CHAR
_ORDER
:
self
.
client
.
send
(
data
)
self
.
client
.
send
(
data
)
input_data
.
append
(
data
[:
-
1
])
input_data
.
append
(
data
[:
-
1
])
multi_char_with_enter
=
True
multi_char_with_enter
=
True
...
...
coco/models.py
View file @
444ba916
...
@@ -22,6 +22,18 @@ class Request:
...
@@ -22,6 +22,18 @@ class Request:
self
.
date_start
=
datetime
.
datetime
.
now
()
self
.
date_start
=
datetime
.
datetime
.
now
()
class
SizedList
(
list
):
def
__init__
(
self
,
maxsize
=
0
):
self
.
maxsize
=
maxsize
self
.
size
=
0
super
()
.
__init__
()
def
append
(
self
,
b
):
if
self
.
maxsize
==
0
or
self
.
size
<
self
.
maxsize
:
super
()
.
append
(
b
)
self
.
size
+=
len
(
b
)
class
Client
:
class
Client
:
"""
"""
Client is the request client. Nothing more to say
Client is the request client. Nothing more to say
...
@@ -78,8 +90,8 @@ class Server:
...
@@ -78,8 +90,8 @@ class Server:
self
.
recv_bytes
=
0
self
.
recv_bytes
=
0
self
.
stop_evt
=
threading
.
Event
()
self
.
stop_evt
=
threading
.
Event
()
self
.
input_data
=
[]
self
.
input_data
=
SizedList
(
maxsize
=
1024
)
self
.
output_data
=
[]
self
.
output_data
=
SizedList
(
maxsize
=
1024
)
self
.
_in_input_state
=
True
self
.
_in_input_state
=
True
self
.
_input_initial
=
False
self
.
_input_initial
=
False
self
.
_in_vim_state
=
False
self
.
_in_vim_state
=
False
...
@@ -118,7 +130,8 @@ class Server:
...
@@ -118,7 +130,8 @@ class Server:
self
.
_input
,
self
.
_output
,
self
.
_input
,
self
.
_output
,
"#"
*
30
+
" End "
+
"#"
*
30
,
"#"
*
30
+
" End "
+
"#"
*
30
,
))
))
self
.
session
.
put_command
(
self
.
_input
,
self
.
_output
)
if
self
.
_input
:
self
.
session
.
put_command
(
self
.
_input
,
self
.
_output
)
del
self
.
input_data
[:]
del
self
.
input_data
[:]
del
self
.
output_data
[:]
del
self
.
output_data
[:]
self
.
_in_input_state
=
True
self
.
_in_input_state
=
True
...
@@ -152,10 +165,14 @@ class Server:
...
@@ -152,10 +165,14 @@ class Server:
return
False
return
False
def
_parse_output
(
self
):
def
_parse_output
(
self
):
if
not
self
.
output_data
:
return
''
parser
=
utils
.
TtyIOParser
()
parser
=
utils
.
TtyIOParser
()
return
parser
.
parse_output
(
self
.
output_data
)
return
parser
.
parse_output
(
self
.
output_data
)
def
_parse_input
(
self
):
def
_parse_input
(
self
):
if
not
self
.
input_data
or
self
.
input_data
[
0
]
==
char
.
RZ_PROTOCOL_CHAR
:
return
parser
=
utils
.
TtyIOParser
()
parser
=
utils
.
TtyIOParser
()
return
parser
.
parse_input
(
self
.
input_data
)
return
parser
.
parse_input
(
self
.
input_data
)
...
@@ -234,3 +251,7 @@ class WSProxy:
...
@@ -234,3 +251,7 @@ class WSProxy:
self
.
child
.
close
()
self
.
child
.
close
()
self
.
ws
.
logout
(
self
.
connection
)
self
.
ws
.
logout
(
self
.
connection
)
logger
.
debug
(
"Proxy {} closed"
.
format
(
self
))
logger
.
debug
(
"Proxy {} closed"
.
format
(
self
))
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