fix: ws取消logout字符串退出,当退出后消息读取EOF退出协程
This commit is contained in:
@@ -196,11 +196,11 @@ func (s *WSController) SSH(c *gin.Context) {
|
||||
wsClient.MsgChan <- msgByte
|
||||
|
||||
// 退出ssh登录
|
||||
if strings.LastIndex(outputStr, "logout\r\n") != -1 {
|
||||
time.Sleep(1 * time.Second)
|
||||
s.wsService.CloseClient(wsClient.ID)
|
||||
return
|
||||
}
|
||||
// if strings.LastIndex(outputStr, "logout\r\n") != -1 {
|
||||
// time.Sleep(1 * time.Second)
|
||||
// s.wsService.CloseClient(wsClient.ID)
|
||||
// return
|
||||
// }
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -283,11 +283,11 @@ func (s *WSController) Telnet(c *gin.Context) {
|
||||
wsClient.MsgChan <- msgByte
|
||||
|
||||
// 退出telnet登录
|
||||
if strings.LastIndex(outputStr, "logout\r\n") != -1 {
|
||||
time.Sleep(1 * time.Second)
|
||||
s.wsService.CloseClient(wsClient.ID)
|
||||
return
|
||||
}
|
||||
// if strings.LastIndex(outputStr, "logout\r\n") != -1 {
|
||||
// time.Sleep(1 * time.Second)
|
||||
// s.wsService.CloseClient(wsClient.ID)
|
||||
// return
|
||||
// }
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/logger"
|
||||
@@ -83,6 +84,11 @@ func (s *WSReceiveImpl) AsyncReceive(client *model.WSClient, reqMsg model.WSRequ
|
||||
logger.Warnf("ws AsyncReceive UID %s err: %s", client.BindUid, err.Error())
|
||||
msgByte, _ := json.Marshal(result.ErrMsg(err.Error()))
|
||||
client.MsgChan <- msgByte
|
||||
if err == io.EOF {
|
||||
// 等待1s后关闭连接
|
||||
time.Sleep(1 * time.Second)
|
||||
client.StopChan <- struct{}{}
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(resByte) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user