tcp socket协议分割解析优化

This commit is contained in:
flswld
2023-04-14 22:07:41 +08:00
parent ae5f2809bf
commit b6be98c58c
7 changed files with 89 additions and 72 deletions

View File

@@ -69,7 +69,6 @@ func (s *Session) recvHandle() {
conn := s.Conn
convId := conn.GetConv()
recvBuf := make([]byte, hk4egatenet.PacketMaxLen)
dataBuf := make([]byte, 0, 1500)
for {
_ = conn.SetReadDeadline(time.Now().Add(time.Second * hk4egatenet.ConnRecvTimeout))
recvLen, err := conn.Read(recvBuf)
@@ -80,7 +79,7 @@ func (s *Session) recvHandle() {
}
recvData := recvBuf[:recvLen]
kcpMsgList := make([]*hk4egatenet.KcpMsg, 0)
hk4egatenet.DecodeBinToPayload(recvData, &dataBuf, convId, &kcpMsgList, s.XorKey)
hk4egatenet.DecodeBinToPayload(recvData, convId, &kcpMsgList, s.XorKey)
for _, v := range kcpMsgList {
protoMsgList := hk4egatenet.ProtoDecode(v, s.ServerCmdProtoMap, s.ClientCmdProtoMap)
for _, vv := range protoMsgList {