From 3e00cdce8c53a0be9a175fce9763067119f18458 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Thu, 16 Oct 2025 23:10:37 +0000 Subject: [PATCH] =?UTF-8?q?```refactor(socket):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E8=BF=9E=E6=8E=A5=E8=AE=A1=E6=95=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96TCP=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=B5=81=E7=A8=8B```?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/socket/ServerEvent.go | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 48a3b054..9d2e6803 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -2,13 +2,13 @@ package socket import ( "context" - "encoding/hex" "fmt" "log" "os" "sync/atomic" "time" + "blazing/common/socket/codec" "blazing/cool" "blazing/logic/service/player" @@ -119,10 +119,10 @@ 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 + // if c.Context().(*player.ClientData).ERROR_CONNUT > 5 { + // return gnet.Close + // } + // c.Context().(*player.ClientData).ERROR_CONNUT += 1 return s.handleTcp(c) } @@ -157,10 +157,14 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) { conn.Context().(*player.ClientData).IsCrossDomain = true data, err := s.codec.Decode(conn) if err != nil { - if conn.Context().(*player.ClientData).ERROR_CONNUT > 5 { + if err != codec.ErrIncompletePacket { action = gnet.Close + } 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) + return gnet.Close + } } - conn.Context().(*player.ClientData).ERROR_CONNUT += 1 } @@ -169,17 +173,6 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) { s.parser(conn, data) }) - if conn.InboundBuffered() > 0 { - - t, _ := conn.Peek(conn.InboundBuffered()) - - fmt.Println("剩余数据", conn.InboundBuffered(), hex.EncodeToString(t)) - 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) - return gnet.Close - } - } - return action }