refactor(wscodec): 重构 WebSocket 编解码逻辑
- 将 WsCodec 结构体中的 upgraded 字段改为 Upgraded,提升代码可读性 - 移除未使用的 Isinitws 字段 - 优化了 Upgrade 方法,使用新命名的字段 - 调整了 ServerEvent 中的 OnTraffic 方法,简化了 WebSocket 消息处理逻辑 - 修改了 controller 中的 Recv 方法,增加了对 WebSocket 消息的处理支持
This commit is contained in:
@@ -13,10 +13,10 @@ import (
|
||||
)
|
||||
|
||||
type WsCodec struct {
|
||||
upgraded bool // 链接是否升级
|
||||
Upgraded bool // 链接是否升级
|
||||
Buf bytes.Buffer // 从实际socket中读取到的数据缓存
|
||||
wsMsgBuf wsMessageBuf // ws 消息缓存
|
||||
Isinitws bool
|
||||
//Isinitws bool
|
||||
}
|
||||
|
||||
type wsMessageBuf struct {
|
||||
@@ -30,7 +30,7 @@ type readWrite struct {
|
||||
}
|
||||
|
||||
func (w *WsCodec) Upgrade(c gnet.Conn) (ok bool, action gnet.Action) {
|
||||
if w.upgraded {
|
||||
if w.Upgraded {
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func (w *WsCodec) Upgrade(c gnet.Conn) (ok bool, action gnet.Action) {
|
||||
logging.Infof("conn[%v] upgrade websocket protocol! Handshake: %v", c.RemoteAddr().String(), hs)
|
||||
|
||||
ok = true
|
||||
w.upgraded = true
|
||||
w.Upgraded = true
|
||||
return
|
||||
}
|
||||
func (w *WsCodec) ReadBufferBytes(c gnet.Conn) (gnet.Action, int) {
|
||||
|
||||
Reference in New Issue
Block a user