修复字典选项和公告提示加载异常,优化tcp和websocket消息处理

This commit is contained in:
孟帅
2023-06-25 19:22:08 +08:00
parent 773f26b479
commit 4a06a895b3
15 changed files with 114 additions and 53 deletions

View File

@@ -3,13 +3,13 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package websocket
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/grpool"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gorilla/websocket"
"net/http"
@@ -19,6 +19,7 @@ var (
ctxManager context.Context // 主上下文
clientManager = NewClientManager() // 客户端管理
routers = make(map[string]EventHandler) // 消息路由
msgGo = grpool.New(20)
upGrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,

View File

@@ -3,10 +3,10 @@
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//
package websocket
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"runtime/debug"
@@ -36,7 +36,20 @@ func handlerMsg(client *Client, message []byte) {
g.Log().Warningf(ctxManager, "handlerMsg function id %v: not registered", request.Event)
return
}
fun(client, request)
err := msgGo.AddWithRecover(ctxManager,
func(ctx context.Context) {
fun(client, request)
},
func(ctx context.Context, err error) {
g.Log().Warningf(ctxManager, "handlerMsg msgGo exec err:%+v", err)
},
)
if err != nil {
g.Log().Warningf(ctxManager, "handlerMsg msgGo Add err:%+v", err)
return
}
}
// RegisterMsg 注册消息