From a7bb0db03aaddb179fd94de05133ec241901d92c Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 1 Apr 2024 16:44:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ws=E5=8F=96=E6=B6=88logout=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E9=80=80=E5=87=BA=EF=BC=8C=E5=BD=93=E9=80=80?= =?UTF-8?q?=E5=87=BA=E5=90=8E=E6=B6=88=E6=81=AF=E8=AF=BB=E5=8F=96EOF?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=8D=8F=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/ws/controller/ws.go | 20 ++++++++++---------- src/modules/ws/service/ws_receive.impl.go | 6 ++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/modules/ws/controller/ws.go b/src/modules/ws/controller/ws.go index b9051c40..50fd01fa 100644 --- a/src/modules/ws/controller/ws.go +++ b/src/modules/ws/controller/ws.go @@ -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 + // } } } }() diff --git a/src/modules/ws/service/ws_receive.impl.go b/src/modules/ws/service/ws_receive.impl.go index 00648e25..3df49304 100644 --- a/src/modules/ws/service/ws_receive.impl.go +++ b/src/modules/ws/service/ws_receive.impl.go @@ -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 {