- fix: no longer fail to parse packet if multiple were received in one read call

- update: max packet size to match client
This commit is contained in:
2025-01-08 12:36:27 -05:00
parent 32fe2d65a7
commit f4a421b7cb
4 changed files with 73 additions and 42 deletions

View File

@@ -25,14 +25,24 @@ impl PacketRouter {
ACTIVE_CONNECTIONS.inc();
while let Some(mut buffer) = pool.acquire().await {
// Read data into the buffer
let n = stream.read(&mut buffer).await?;
let mut header_handle = stream.take(6);
let n = header_handle.read(&mut buffer).await?;
if n == 0 {
break; // Connection closed
}
let packet_size = u16::from_le_bytes(buffer[0..2].try_into()?) as usize;
if packet_size > 6 {
let mut body_handle = stream.take((packet_size-6) as u64);
let n = body_handle.read(&mut buffer[6..]).await?;
if n == 0 {
break; // Connection closed
}
}
PACKETS_RECEIVED.inc();
// Process the packet
match Packet::from_raw(&buffer[..n]) {
match Packet::from_raw(&buffer[..packet_size]) {
Ok(packet) => {
debug!("Parsed Packet: {:?}", packet);
// Handle the parsed packet (route it, process it, etc.)