Unverified Commit 2c2edf3c authored by Eric_Lee's avatar Eric_Lee Committed by GitHub

Merge pull request #151 from jumpserver/dev

Dev
parents ad9d62b9 a1b2ff4b
...@@ -33,14 +33,29 @@ type CmdParser struct { ...@@ -33,14 +33,29 @@ type CmdParser struct {
} }
func (cp *CmdParser) WriteData(p []byte) (int, error) { func (cp *CmdParser) WriteData(p []byte) (int, error) {
select {
case <-cp.closed:
return 0, io.EOF
default:
}
return cp.writer.Write(p) return cp.writer.Write(p)
} }
func (cp *CmdParser) Write(p []byte) (int, error) { func (cp *CmdParser) Write(p []byte) (int, error) {
select {
case <-cp.closed:
return 0, io.EOF
default:
}
return len(p), nil return len(p), nil
} }
func (cp *CmdParser) Read(p []byte) (int, error) { func (cp *CmdParser) Read(p []byte) (int, error) {
select {
case <-cp.closed:
return 0, io.EOF
default:
}
return cp.reader.Read(p) return cp.reader.Read(p)
} }
...@@ -51,6 +66,7 @@ func (cp *CmdParser) Close() error { ...@@ -51,6 +66,7 @@ func (cp *CmdParser) Close() error {
default: default:
close(cp.closed) close(cp.closed)
} }
_ = cp.reader.Close()
return cp.writer.Close() return cp.writer.Close()
} }
...@@ -94,7 +110,11 @@ func (cp *CmdParser) parsePS1(s string) string { ...@@ -94,7 +110,11 @@ func (cp *CmdParser) parsePS1(s string) string {
// Parse 解析命令或输出 // Parse 解析命令或输出
func (cp *CmdParser) Parse() string { func (cp *CmdParser) Parse() string {
select {
case <-cp.closed:
default:
cp.writer.Write([]byte("\r")) cp.writer.Write([]byte("\r"))
}
cp.lock.Lock() cp.lock.Lock()
defer cp.lock.Unlock() defer cp.lock.Unlock()
output := strings.TrimSpace(strings.Join(cp.currentLines, "\r\n")) output := strings.TrimSpace(strings.Join(cp.currentLines, "\r\n"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment