``refactor(socket): 移除错误连接计数逻辑,优化TCP数据处理流程``
This commit is contained in:
@@ -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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user