This commit is contained in:
Liang Ding 2019-05-16 13:52:18 +08:00
parent 93a64bb9d7
commit c62d40e3a9
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
1 changed files with 8 additions and 12 deletions

View File

@ -170,11 +170,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
}
oneRuneStr := string(r)
buf.content += oneRuneStr
now := time.Now().UnixNano() / int64(time.Millisecond)
if 0 == buf.millisecond {
buf.millisecond = now
}
@ -184,10 +181,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
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 {
logger.Warn(err)
@ -202,10 +197,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
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)
@ -229,11 +222,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
}
oneRuneStr := string(r)
buf.content += oneRuneStr
now := time.Now().UnixNano() / int64(time.Millisecond)
if 0 == buf.millisecond {
buf.millisecond = now
}
@ -241,9 +231,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
if now-outputTimeout >= buf.millisecond || len(buf.content) > outputBufMax || oneRuneStr == "\n" {
channelRet["cmd"] = "run"
channelRet["output"] = buf.content
buf = outputBuf{} // a new buffer
err = wsChannel.WriteJSON(&channelRet)
if nil != err {
logger.Warn(err)
@ -253,6 +241,14 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
wsChannel.Refresh()
}
}
cmd.Wait()
if 124 == cmd.ProcessState.ExitCode() {
channelRet["cmd"] = "run-done"
channelRet["output"] = "<span class='stderr'>run program timeout in 5s</span>\n"
wsChannel.WriteJSON(&channelRet)
wsChannel.Refresh()
}
}(rand.Int())
}