refactor(socket): 优化TCP连接处理逻辑,新增错误连接计数并调整返回值处理
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user