From 083781737ae701a8bdb18b1a43e386968d0504a8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 15:34:30 +0800 Subject: [PATCH 1/5] 1 --- server/websocket/internal/logic/datatransferlogic.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index b62f4dca..c315a036 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -300,7 +300,7 @@ func (w *wsConnectItem) readLoop() { select { case <-w.closeChan: //如果关闭了 return - default: + default: //收取消息 msgType, data, err := w.conn.ReadMessage() if err != nil { logx.Error("接受信息错误:", err) @@ -310,8 +310,12 @@ func (w *wsConnectItem) readLoop() { } //ping的消息不处理 if msgType != websocket.PingMessage { - //消息传入缓冲通道 - w.inChan <- data + select { + case w.inChan <- data: //消息传入缓冲通道 + continue + case <-time.After(time.Second * 3): //3秒放不进去就丢弃 + continue + } } } } From d4b6ef5d7c8412dbc812aac991886e762d4f1660 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 15:37:45 +0800 Subject: [PATCH 2/5] 1 --- server/websocket/internal/logic/datatransferlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index c315a036..1563ee42 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -308,8 +308,8 @@ func (w *wsConnectItem) readLoop() { w.close() return } - //ping的消息不处理 - if msgType != websocket.PingMessage { + //ping/pong/close的消息不处理 + if msgType != websocket.PingMessage && msgType != websocket.PongMessage && msgType != websocket.CloseMessage { select { case w.inChan <- data: //消息传入缓冲通道 continue From b03f87c91904cebc6f63b81156ae778b85a87fad Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 15:40:56 +0800 Subject: [PATCH 3/5] 1 --- .../internal/logic/homepagerecommendproductlistlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 389a01e0..2b5f27fa 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -56,7 +56,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the merchant category is not exists") + return resp.SetStatusWithMessage(basic.CodeOK, "the merchant category is not exists", []interface{}{}) } logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant category") @@ -66,7 +66,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindDefualtOne(l.ctx) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the default merchant category is not exists") + return resp.SetStatusWithMessage(basic.CodeOK, "the default merchant category is not exists", []interface{}{}) } logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default merchant category") From bb8c80d7f7bd0289515a8b6f991d52c3cf8dd25c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 15:47:25 +0800 Subject: [PATCH 4/5] 1 --- .../internal/logic/datatransferlogic.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 1563ee42..c61507af 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -310,12 +310,7 @@ func (w *wsConnectItem) readLoop() { } //ping/pong/close的消息不处理 if msgType != websocket.PingMessage && msgType != websocket.PongMessage && msgType != websocket.CloseMessage { - select { - case w.inChan <- data: //消息传入缓冲通道 - continue - case <-time.After(time.Second * 3): //3秒放不进去就丢弃 - continue - } + w.sendToInChan(data) } } } @@ -350,6 +345,18 @@ func (w *wsConnectItem) sendToOutChan(data []byte) { } } +// 发送接受到的消息到入口缓冲队列中 +func (w *wsConnectItem) sendToInChan(data []byte) { + select { + case <-w.closeChan: //关闭了 + return + case w.inChan <- data: + return + case <-time.After(time.Second * 3): //3秒超时丢弃 + return + } +} + // 格式化为websocket标准返回格式 func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte { d := websocket_data.DataTransferData{ From 22e62e1e0506f2c396480730365e8221412948b0 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 15:50:18 +0800 Subject: [PATCH 5/5] 1 --- .../websocket/internal/logic/datatransferlogic.go | 14 +++++++------- server/websocket/internal/logic/ws_render_image.go | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index c61507af..7c97ec08 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -59,7 +59,7 @@ var ( CheckOrigin: func(r *http.Request) bool { return true }, - //写的缓存池 + //写的缓冲队列 WriteBufferPool: &buffPool, //是否支持压缩 EnableCompression: false, @@ -75,8 +75,8 @@ type wsConnectItem struct { closeChan chan struct{} //ws连接关闭chan(基本属性) isClose bool //是否已经关闭(基本属性) uniqueId string //ws连接唯一标识(基本属性) - inChan chan []byte //接受消息缓冲池(基本属性) - outChan chan []byte //要发送回客户端的消息缓冲池(基本属性) + inChan chan []byte //接受消息缓冲队列(基本属性) + outChan chan []byte //要发送回客户端的消息缓冲队列(基本属性) mutex sync.Mutex //互斥锁(基本属性) userId int64 //用户id(基本属性) guestId int64 //游客id(基本属性) @@ -268,7 +268,7 @@ func (w *wsConnectItem) close() { logx.Info("###websocket:", w.uniqueId, " uid:", w.userId, " gid:", w.guestId, " is closed") } -// 读取出口缓冲池数据输出返回给浏览器端 +// 读取出口缓冲队列数据输出返回给浏览器端 func (w *wsConnectItem) writeLoop() { defer func() { if err := recover(); err != nil { @@ -289,7 +289,7 @@ func (w *wsConnectItem) writeLoop() { } } -// 接受客户端发来的消息并写入入口缓冲池 +// 接受客户端发来的消息并写入入口缓冲队列 func (w *wsConnectItem) readLoop() { defer func() { if err := recover(); err != nil { @@ -333,7 +333,7 @@ func (w *wsConnectItem) sendLoop() { } } -// 把要传递给客户端的数据放入出口缓冲池 +// 把要传递给客户端的数据放入出口缓冲队列 func (w *wsConnectItem) sendToOutChan(data []byte) { select { case <-w.closeChan: @@ -367,7 +367,7 @@ func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data inte return b } -// 处理入口缓冲池中不同类型的数据(分发处理) +// 处理入口缓冲队列中不同类型的数据(分发处理) func (w *wsConnectItem) dealwithReciveData(data []byte) { var parseInfo websocket_data.DataTransferData if err := json.Unmarshal(data, &parseInfo); err != nil { diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index b2ac63b7..123545ff 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -44,19 +44,19 @@ type renderTask struct { uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 } -// 发送到渲染缓冲池 +// 发送到渲染缓冲队列 func (w *wsConnectItem) sendToRenderChan(data []byte) { select { case <-w.closeChan: //已经关闭 return - case w.extendRenderProperty.renderChan <- data: //发入到缓冲池 + case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 return - case <-time.After(time.Second * 3): //三秒没进入缓冲池就丢弃 + case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃 return } } -// 渲染发送到组装数据组装数据(缓冲池) +// 渲染发送到组装数据组装数据(缓冲队列) func (w *wsConnectItem) renderImage() { for { select {