fix(socket): 修复TCP连接处理逻辑与数据包解析问题

- 在 `ServerEvent.go` 中,移除无效的错误连接计数逻辑,明确标识 TCP 连接并直接调用 `handleTcp`
- 优化 `handleTcp` 方法中对数据解析
This commit is contained in:
2025-10-17 10:47:17 +08:00
parent c9c58a4087
commit 5f8c18e7d8
2 changed files with 19 additions and 21 deletions

View File

@@ -119,10 +119,8 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
return action
}
if !ok { //升级失败,说明是tcp连接
// if c.Context().(*player.ClientData).ERROR_CONNUT > 5 {
// return gnet.Close
// }
// c.Context().(*player.ClientData).ERROR_CONNUT += 1
ws.Tcp = true
return s.handleTcp(c)
}
@@ -159,6 +157,7 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
if err != nil {
if err != codec.ErrIncompletePacket {
action = gnet.Close
return
} else {
if err := conn.Wake(nil); err != nil { // wake up the connection manually to avoid missing the leftover data
logging.Errorf("failed to wake up the connection, %v", err)
@@ -168,10 +167,12 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
}
//client := conn.RemoteAddr().String()
_ = s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
s.parser(conn, data)
})
if data != nil {
//client := conn.RemoteAddr().String()
_ = s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
s.parser(conn, data)
})
}
return action