``fix(socket): 优化TCP断包处理逻辑,添加调试日志和唤醒机制``
This commit is contained in:
@@ -155,14 +155,17 @@ 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 err != codec.ErrIncompletePacket {
|
||||
action = gnet.Close
|
||||
return
|
||||
} else {
|
||||
|
||||
if err == codec.ErrIncompletePacket&&conn.InboundBuffered()>0 {
|
||||
t, _ := conn.Peek(conn.InboundBuffered())
|
||||
cool.Loger.Debug(context.Background(), "断包", err.Error(), conn.InboundBuffered(), 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
|
||||
}
|
||||
} else {
|
||||
action = gnet.Close
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user