private void OnReadToPacket() { __bodySize = 0; while (true) { if (__bodySize == 0) { if (_readBuffer.GetSize() < NetPacketHeader.HEAD_SIZE) { return; } if (!_readBuffer.Read(__headerbuf, NetPacketHeader.HEAD_SIZE)) { this.LogError("failed read packet header !"); return; } __bodySize = NetworkTools.ReadInt32FromBuffer(__headerbuf, 0); __opcode = NetworkTools.ReadInt32FromBuffer(__headerbuf, 4); } if (__bodySize > 0 && _readBuffer.GetSize() < __bodySize) { this.LogError("body字节数不够,异常!!"); return; } NetPacket packet = _clientSession.SpawnPacket(); packet.opcode = (ushort)__OnRead_header.cmd; if (__bodySize > 0) { CheckBufferSize(ref __OnRead_temp_buf, __bodySize); if (!_readBuffer.Read(__OnRead_temp_buf, (uint)__bodySize)) { this.LogError("failed read packet body !"); } packet.In(__OnRead_temp_buf, (uint)__bodySize); } __bodySize = 0; _clientSession.OnRecivePacket(packet); } }