make packet size a const

This commit is contained in:
griffi-gh 2023-03-07 21:18:59 +01:00
parent 4c31eab0f4
commit 6a9dc49529
3 changed files with 7 additions and 4 deletions

View file

@ -9,7 +9,7 @@ use std::{
use crate::{
BINCODE_CONFIG,
packet::{ClientPacket, IdClientPacket, IdServerPacket, ServerPacket, Message},
common::{ClientId, PROTOCOL_ID, DEFAULT_USER_PROTOCOL_ID}
common::{ClientId, PROTOCOL_ID, DEFAULT_USER_PROTOCOL_ID, PACKET_SIZE}
};
#[derive(Default, Clone, Debug)]
@ -201,7 +201,7 @@ impl<S, R> Client<S, R> where S: Message, R: Message {
self.last_heartbeat = Instant::now();
}
//receive
let mut buf = [0; u16::MAX as usize];
let mut buf = [0; PACKET_SIZE];
loop {
match self.socket.recv(&mut buf) {
Ok(length) => {

View file

@ -2,7 +2,10 @@ use std::num::NonZeroU8;
pub type ClientId = NonZeroU8;
pub type ClientIdRepr = u8;
pub const MAX_CLIENTS: usize = u8::MAX as _;
pub const PROTOCOL_ID: u16 = 1;
pub const DEFAULT_USER_PROTOCOL_ID: u16 = 0xffff;
pub const PACKET_SIZE: usize = u16::MAX as usize;

View file

@ -10,7 +10,7 @@ use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
use crate::{
BINCODE_CONFIG,
common::{ClientId, ClientIdRepr, MAX_CLIENTS, PROTOCOL_ID, DEFAULT_USER_PROTOCOL_ID},
common::{ClientId, ClientIdRepr, MAX_CLIENTS, PROTOCOL_ID, DEFAULT_USER_PROTOCOL_ID, PACKET_SIZE},
packet::{IdClientPacket, ClientPacket, ServerPacket, IdServerPacket, Message}
};
@ -177,7 +177,7 @@ impl<S, R> Server<S, R> where S: Message, R: Message {
true
});
let mut buf = [0; u16::MAX as usize];
let mut buf = [0; PACKET_SIZE];
loop {
match self.socket.recv_from(&mut buf) {
Ok((len, addr)) => {