fix: Fixes thread guard and cleans up incoming packet reader (#1641)

### Summary
* Fixes syntax compile error when THREADGUARD is enabled.
* Removes `int packetLength` from incoming packet handles since they aren't needed.

### Developer Notes
Incoming packet handler `SpanReader` is now properly scoped to that packet by length.
This commit is contained in:
Kamron Batman 2023-12-19 17:04:09 -08:00 committed by GitHub
parent 25a75fdf24
commit 7d9bc9ff0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 190 additions and 157 deletions

View file

@ -469,7 +469,9 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
Console.WriteLine("Attempting to get pipe buffer from wrong thread!");
Console.WriteLine(new StackTrace());
Utility.PopColor();
return;
buffer = Array.Empty<byte>();
return false;
}
#endif
buffer = SendPipe.Writer.AvailableToWrite();
@ -842,12 +844,16 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
UpdatePacketCount(packetId);
var packetBuffer = packetReader.Buffer[..packetLength];
if (PacketLogging)
{
LogPacket(packetReader.Buffer[..packetLength], true);
LogPacket(packetBuffer, true);
}
handler.OnReceive(this, packetReader, packetLength);
// Make a new SpanReader that is limited to the length of the packet.
// This allows us to use reader.Remaining for VendorBuyReply packet
handler.OnReceive(this, new SpanReader(packetBuffer));
prof?.Finish(packetLength);