Skip to content

Commit

Permalink
Fix buffer size issue on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapieaapie1 committed Dec 4, 2022
1 parent fcacfd9 commit bd85423
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "f1-2022-udp-server"
description = "A UDP server library for F1 2022"
license = "MIT"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
homepage = "https://github.com/jaapieaapie1/F1-2022-telemetry-rust"
exclude = [".idea/", "target/"]
Expand Down
11 changes: 9 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Server {
}

pub fn read_packet(&self) -> io::Result<Packets> {
let mut buf: [u8; PacketHeader::PACKET_SIZE] = [0; PacketHeader::PACKET_SIZE];
let mut buf: [u8; Self::calculate_size(PacketHeader::PACKET_SIZE)] = [0; Self::calculate_size(PacketHeader::PACKET_SIZE)];
self.stream.peek(&mut buf)?;

let header = PacketHeader::new(&mut ByteBuffer::from_bytes(&buf))?;
Expand Down Expand Up @@ -87,10 +87,17 @@ impl Server {
}

fn read_packet_dynamically<P: Packet>(&self) -> io::Result<P> {
let mut buf: Vec<u8> = vec![0; P::get_packet_size()];
let mut buf: Vec<u8> = vec![0; Self::calculate_size(P::get_packet_size())];
self.stream.recv(&mut buf)?;

P::new(&mut ByteBuffer::from_bytes(&buf))
}

pub const fn calculate_size(size: usize) -> usize {
if cfg!(windows) {
return size + 2048
}
size
}
}

0 comments on commit bd85423

Please sign in to comment.