refactor(socket): 优化TCP连接处理逻辑,新增错误连接计数并调整返回值处理

This commit is contained in:
1
2025-09-27 17:35:12 +00:00
parent d7712ef70f
commit 290e678559
2 changed files with 9 additions and 8 deletions

View File

@@ -84,8 +84,8 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
ws := c.Context().(*player.ClientData).Wsmsg
if ws.Tcp { //升级失败时候防止缓冲区溢出
s.handleTcp(c)
return gnet.None
FF := s.handleTcp(c)
return FF
}
tt, len1 := ws.ReadBufferBytes(c)
@@ -97,7 +97,7 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
ok, action := ws.Upgrade(c)
if !ok { //升级失败,说明是tcp连接
s.handleTcp(c)
return gnet.None
return action
} else {
// fmt.Println(ws.Buf.Bytes())
c.Read(make([]byte, len1))
@@ -132,6 +132,10 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
}
data, err := s.codec.Decode(conn)
if err != nil {
if conn.Context().(*player.ClientData).ERROR_CONNUT > 5 {
action = gnet.Close
}
conn.Context().(*player.ClientData).ERROR_CONNUT += 1
break
}
@@ -140,7 +144,7 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
s.parser(conn, data)
})
return gnet.None
return
}
if conn.InboundBuffered() > 0 {