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