diff --git a/.gitignore b/.gitignore index b86aaa6f3..906497de1 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ logic/logic2 login/login login/login logic/logic1 +logic/logic1 diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index ced004b64..1878bcf4b 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -83,6 +83,7 @@ func (s *Server) OnOpen(conn gnet.Conn) (out []byte, action gnet.Action) { if s.network != "tcp" { return nil, gnet.Close } + conn.SetReadDeadline(<-time.After(3000)) if conn.Context() == nil { conn.SetContext(player.NewClientData(conn)) //注入data @@ -156,10 +157,8 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) { data, err := s.codec.Decode(conn) if err != nil { if err == codec.ErrIncompletePacket { - if err := conn.Wake(nil); err != nil { // wake up the connection manually to avoid missing the leftover data - cool.Loger.Errorf(context.Background(), "failed to wake up the connection, %v", err) - return gnet.Close - } + + return } return gnet.Close diff --git a/common/socket/codec/SocketCodec_Tomee.go b/common/socket/codec/SocketCodec_Tomee.go index e8a954371..6acd1dd4f 100644 --- a/common/socket/codec/SocketCodec_Tomee.go +++ b/common/socket/codec/SocketCodec_Tomee.go @@ -10,7 +10,7 @@ import ( var ErrIncompletePacket = errors.New("incomplete packet") -const maxBodyLen = 10 * 1024 * 1024 // 业务最大包体长度,按需调整 +const maxBodyLen = 10 * 1024 // 业务最大包体长度,按需调整 // TomeeSocketCodec 协议格式: // // * 0 4 @@ -67,7 +67,7 @@ func (codec TomeeSocketCodec) Decode(c gnet.Conn) ([]byte, error) { return nil, ErrIncompletePacket } // 提取包体 - body, _ := c.Next(int(bodyLen)) + body, err := c.Next(int(bodyLen)) - return body, nil + return body, err } diff --git a/logic/logic1 b/logic/logic1 index 1667f8f1a..8dc60e132 100644 Binary files a/logic/logic1 and b/logic/logic1 differ