修复关闭的会话仍然显示在线的问题 fixes #25

This commit is contained in:
dushixiang
2021-01-12 21:37:27 +08:00
parent 6f2bf6c9ba
commit 3bb7d2d49b
7 changed files with 49 additions and 23 deletions

View File

@ -12,6 +12,7 @@ import (
)
const (
TunnelClosed int = -1
Normal int = 0
NotFoundSession int = 2000
NewTunnelError int = 2001
@ -155,12 +156,12 @@ func TunEndpoint(c echo.Context) error {
for true {
instruction, err := tunnel.Read()
if err != nil {
CloseSessionById(sessionId, Normal, "")
CloseSessionById(sessionId, TunnelClosed, "隧道已关闭")
break
}
err = ws.WriteMessage(websocket.TextMessage, instruction)
if err != nil {
CloseSessionById(sessionId, Normal, "")
CloseSessionById(sessionId, TunnelClosed, "隧道已关闭")
break
}
}
@ -169,12 +170,12 @@ func TunEndpoint(c echo.Context) error {
for true {
_, message, err := ws.ReadMessage()
if err != nil {
CloseSessionById(sessionId, Normal, "")
CloseSessionById(sessionId, Normal, "用户主动关闭了会话")
break
}
_, err = tunnel.WriteAndFlush(message)
if err != nil {
CloseSessionById(sessionId, Normal, "")
CloseSessionById(sessionId, Normal, "用户主动关闭了会话")
break
}
}