mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 13:18:21 -06:00
make packet size a const
This commit is contained in:
parent
4c31eab0f4
commit
6a9dc49529
|
@ -9,7 +9,7 @@ use std::{
|
||||||
use crate::{
|
use crate::{
|
||||||
BINCODE_CONFIG,
|
BINCODE_CONFIG,
|
||||||
packet::{ClientPacket, IdClientPacket, IdServerPacket, ServerPacket, Message},
|
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)]
|
#[derive(Default, Clone, Debug)]
|
||||||
|
@ -201,7 +201,7 @@ impl<S, R> Client<S, R> where S: Message, R: Message {
|
||||||
self.last_heartbeat = Instant::now();
|
self.last_heartbeat = Instant::now();
|
||||||
}
|
}
|
||||||
//receive
|
//receive
|
||||||
let mut buf = [0; u16::MAX as usize];
|
let mut buf = [0; PACKET_SIZE];
|
||||||
loop {
|
loop {
|
||||||
match self.socket.recv(&mut buf) {
|
match self.socket.recv(&mut buf) {
|
||||||
Ok(length) => {
|
Ok(length) => {
|
||||||
|
|
|
@ -2,7 +2,10 @@ use std::num::NonZeroU8;
|
||||||
|
|
||||||
pub type ClientId = NonZeroU8;
|
pub type ClientId = NonZeroU8;
|
||||||
pub type ClientIdRepr = u8;
|
pub type ClientIdRepr = u8;
|
||||||
|
|
||||||
pub const MAX_CLIENTS: usize = u8::MAX as _;
|
pub const MAX_CLIENTS: usize = u8::MAX as _;
|
||||||
|
|
||||||
pub const PROTOCOL_ID: u16 = 1;
|
pub const PROTOCOL_ID: u16 = 1;
|
||||||
pub const DEFAULT_USER_PROTOCOL_ID: u16 = 0xffff;
|
pub const DEFAULT_USER_PROTOCOL_ID: u16 = 0xffff;
|
||||||
|
|
||||||
|
pub const PACKET_SIZE: usize = u16::MAX as usize;
|
||||||
|
|
|
@ -10,7 +10,7 @@ use hashbrown::HashMap;
|
||||||
use nohash_hasher::BuildNoHashHasher;
|
use nohash_hasher::BuildNoHashHasher;
|
||||||
use crate::{
|
use crate::{
|
||||||
BINCODE_CONFIG,
|
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}
|
packet::{IdClientPacket, ClientPacket, ServerPacket, IdServerPacket, Message}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ impl<S, R> Server<S, R> where S: Message, R: Message {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut buf = [0; u16::MAX as usize];
|
let mut buf = [0; PACKET_SIZE];
|
||||||
loop {
|
loop {
|
||||||
match self.socket.recv_from(&mut buf) {
|
match self.socket.recv_from(&mut buf) {
|
||||||
Ok((len, addr)) => {
|
Ok((len, addr)) => {
|
||||||
|
|
Loading…
Reference in a new issue