From f04330c85d4301dd1118786bc09db1d7479bfece Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 11:13:10 +0800 Subject: [PATCH] fix --- .../internal/logic/datatransferlogic.go | 52 +++++++++---------- .../internal/logic/ws_render_image.go | 4 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 53a2d2c6..5ff61648 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -133,15 +133,15 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) return } //循环读客户端信息 - go ws.readLoop() - //循环把数据发送给客户端 - go ws.writeLoop() - //推消息到云渲染 - go ws.sendLoop() + go ws.acceptBrowserMessage() + //消费出口数据并发送浏览器端 + go ws.consumeOutChanData() + //消费入口数据 + go ws.consumeInChanData() //操作连接中渲染任务的增加/删除 go ws.operationRenderTask() //消费渲染缓冲队列 - go ws.renderImage() + go ws.consumeRenderImageData() //心跳 ws.heartbeat() } @@ -277,7 +277,7 @@ func (w *wsConnectItem) close() { } // 读取出口缓冲队列数据输出返回给浏览器端 -func (w *wsConnectItem) writeLoop() { +func (w *wsConnectItem) consumeOutChanData() { defer func() { if err := recover(); err != nil { logx.Error("write loop panic:", err) @@ -297,8 +297,25 @@ func (w *wsConnectItem) writeLoop() { } } -// 接受客户端发来的消息并写入入口缓冲队列 -func (w *wsConnectItem) readLoop() { +// 消费websocket入口数据池中的数据 +func (w *wsConnectItem) consumeInChanData() { + defer func() { + if err := recover(); err != nil { + logx.Error("send loop panic:", err) + } + }() + for { + select { + case <-w.closeChan: + return + case data := <-w.inChan: + w.dealwithReciveData(data) + } + } +} + +// 接受浏览器端发来的消息并写入入口缓冲队列 +func (w *wsConnectItem) acceptBrowserMessage() { defer func() { if err := recover(); err != nil { logx.Error("read loop panic:", err) @@ -324,23 +341,6 @@ func (w *wsConnectItem) readLoop() { } } -// 消费websocket入口数据池中的数据 -func (w *wsConnectItem) sendLoop() { - defer func() { - if err := recover(); err != nil { - logx.Error("send loop panic:", err) - } - }() - for { - select { - case <-w.closeChan: - return - case data := <-w.inChan: - w.dealwithReciveData(data) - } - } -} - // 把要传递给客户端的数据放入出口缓冲队列 func (w *wsConnectItem) sendToOutChan(data []byte) { select { diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index d9a513f8..bab88207 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -56,8 +56,8 @@ func (w *wsConnectItem) sendToRenderChan(data []byte) { } } -// 渲染发送到组装数据组装数据(缓冲队列) -func (w *wsConnectItem) renderImage() { +// 消费渲染缓冲队列数据 +func (w *wsConnectItem) consumeRenderImageData() { defer func() { if err := recover(); err != nil { logx.Error("func renderImage err:", err)