fix buffer size passed to socket.recv_from

This commit is contained in:
Hailey Somerville 2023-08-22 19:51:40 +10:00
parent e90f25f8b0
commit fa1d3fc68b
2 changed files with 5 additions and 1 deletions

View file

@ -38,7 +38,7 @@ impl Protocol {
loop { loop {
let mut buffer = PacketBuffer::allocate(); let mut buffer = PacketBuffer::allocate();
let (nbytes, peer) = self.socket.recv_from(buffer.as_bytes_mut())?; let (nbytes, peer) = self.socket.recv_from(buffer.as_full_buffer_mut())?;
buffer.set_len(nbytes); buffer.set_len(nbytes);
if let Some(packet) = Packet::from_buffer(buffer) { if let Some(packet) = Packet::from_buffer(buffer) {

View file

@ -49,6 +49,10 @@ impl PacketBuffer {
pub fn as_bytes_mut(&mut self) -> &mut [u8] { pub fn as_bytes_mut(&mut self) -> &mut [u8] {
&mut self.raw[0..self.len] &mut self.raw[0..self.len]
} }
pub fn as_full_buffer_mut(&mut self) -> &mut [u8] {
&mut self.raw
}
} }
#[derive(Debug)] #[derive(Debug)]