This commit is contained in:
parent
487d97d844
commit
0062c28edb
|
@ -32,7 +32,7 @@ import (
|
||||||
const (
|
const (
|
||||||
outputBufMax = 1024 // 1024 string(rune)
|
outputBufMax = 1024 // 1024 string(rune)
|
||||||
outputTimeout = 100 // 100ms
|
outputTimeout = 100 // 100ms
|
||||||
outputCountMax = 10 // 10 reads
|
outputCountMax = 30 // 30 reads
|
||||||
)
|
)
|
||||||
|
|
||||||
type outputBuf struct {
|
type outputBuf struct {
|
||||||
|
|
|
@ -29,8 +29,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
outputBufMax = 128 // 128 string(rune)
|
outputBufMax = 1024 // 1024 string(rune)
|
||||||
outputTimeout = 100 // 100ms
|
outputTimeout = 100 // 100ms
|
||||||
|
outputCountMax = 30 // 30 reads
|
||||||
)
|
)
|
||||||
|
|
||||||
type outputBuf struct {
|
type outputBuf struct {
|
||||||
|
@ -133,6 +134,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
defer util.Recover()
|
defer util.Recover()
|
||||||
|
|
||||||
buf := outputBuf{}
|
buf := outputBuf{}
|
||||||
|
count := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
wsChannel := session.PlaygroundWS[sid]
|
wsChannel := session.PlaygroundWS[sid]
|
||||||
|
@ -141,6 +143,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r, _, err := outReader.ReadRune()
|
r, _, err := outReader.ReadRune()
|
||||||
|
count++
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
// remove the exited process from user process set
|
// remove the exited process from user process set
|
||||||
|
@ -171,11 +174,14 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
buf.millisecond = now
|
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["cmd"] = "run"
|
||||||
channelRet["output"] = buf.content
|
channelRet["output"] = buf.content
|
||||||
|
|
||||||
buf = outputBuf{} // a new buffer
|
buf = outputBuf{} // a new buffer
|
||||||
|
count = 0 // clear count
|
||||||
|
|
||||||
err = wsChannel.WriteJSON(&channelRet)
|
err = wsChannel.WriteJSON(&channelRet)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
@ -184,6 +190,26 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wsChannel.Refresh()
|
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