- 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:
@@ -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.)
|
||||
|
||||
Reference in New Issue
Block a user