Commit 04761ec3 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 TCPConn 启动CRC后,数据包异常,数据的长度0,就会出错

parent ea4f1e33
......@@ -113,7 +113,13 @@ namespace FObjBase
return -1;
}
else if (plen < 2) {
//异常,包最短也有2个byte
logger.Error($"TCPConn GetRecvInfoPacket 包.Size = {plen},太小,不正常, 断开重新连接");
sock.Close();
return -1;
}
if (len < plen)
{
return 0;
......@@ -121,6 +127,14 @@ namespace FObjBase
if (HasCRC) //TODO
{
if (plen < 4) {
//
logger.Error("TCPConn GetRecvInfoPacket 包.Size < 4, 无法 CRC 校验。 断开重新连接");
sock.Close();
return -1;
}
UInt16 crc = Misc.CRC.CRC16(in_buffer, 0, plen - 2);
int packet_crc_idx = plen - 2;
UInt16 packet_crc = BitConverter.ToUInt16(in_buffer.GetRange(packet_crc_idx, 2).ToArray(), 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment