Fix #277
This commit is contained in:
parent
6b4ec1b924
commit
487d97d844
|
@ -30,8 +30,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
outputBufMax = 128 // 128 string(rune)
|
||||
outputTimeout = 100 // 100ms
|
||||
outputBufMax = 1024 // 1024 string(rune)
|
||||
outputTimeout = 100 // 100ms
|
||||
outputCountMax = 10 // 10 reads
|
||||
)
|
||||
|
||||
type outputBuf struct {
|
||||
|
@ -136,6 +137,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
defer util.Recover()
|
||||
|
||||
buf := outputBuf{}
|
||||
count := 0
|
||||
|
||||
for {
|
||||
wsChannel := session.OutputWS[sid]
|
||||
|
@ -144,6 +146,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
r, _, err := outReader.ReadRune()
|
||||
count++
|
||||
|
||||
if nil != err {
|
||||
// remove the exited process from user's process set
|
||||
|
@ -177,11 +180,14 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
buf.millisecond = now
|
||||
}
|
||||
|
||||
if now-outputTimeout >= buf.millisecond || len(buf.content) > outputBufMax || oneRuneStr == "\n" {
|
||||
flood := count > outputCountMax
|
||||
|
||||
if "\n" == oneRuneStr && !flood {
|
||||
channelRet["cmd"] = "run"
|
||||
channelRet["output"] = buf.content
|
||||
|
||||
buf = outputBuf{} // a new buffer
|
||||
count = 0 // clear count
|
||||
|
||||
err = wsChannel.WriteJSON(&channelRet)
|
||||
if nil != err {
|
||||
|
@ -190,6 +196,26 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
wsChannel.Refresh()
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if now-outputTimeout >= buf.millisecond || len(buf.content) > outputBufMax {
|
||||
channelRet["cmd"] = "run"
|
||||
channelRet["output"] = buf.content
|
||||
|
||||
buf = outputBuf{} // a new buffer
|
||||
count = 0 // clear count
|
||||
|
||||
err = wsChannel.WriteJSON(&channelRet)
|
||||
if nil != err {
|
||||
logger.Warn(err)
|
||||
break
|
||||
}
|
||||
|
||||
wsChannel.Refresh()
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue