mirror of
https://github.com/timvisee/lazymc.git
synced 2025-05-19 12:50:23 -07:00
Increase buffer size for reading Minecraft packets
This commit is contained in:
parent
90e64297c0
commit
ffc4f00430
@ -32,6 +32,9 @@ pub const PROTO_DEFAULT_PROTOCOL: u32 = 756;
|
|||||||
// TODO: read this from server.properties instead
|
// TODO: read this from server.properties instead
|
||||||
pub const COMPRESSION_THRESHOLD: i32 = 256;
|
pub const COMPRESSION_THRESHOLD: i32 = 256;
|
||||||
|
|
||||||
|
/// Default buffer size when reading packets.
|
||||||
|
const BUF_SIZE: usize = 8 * 1024;
|
||||||
|
|
||||||
/// Minecraft protocol packet IDs.
|
/// Minecraft protocol packet IDs.
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub mod packets {
|
pub mod packets {
|
||||||
@ -323,7 +326,7 @@ pub async fn read_packet(
|
|||||||
// Keep reading until we have at least 2 bytes
|
// Keep reading until we have at least 2 bytes
|
||||||
while buf.len() < 2 {
|
while buf.len() < 2 {
|
||||||
// Read packet from socket
|
// Read packet from socket
|
||||||
let mut tmp = Vec::with_capacity(64);
|
let mut tmp = Vec::with_capacity(BUF_SIZE);
|
||||||
match stream.read_buf(&mut tmp).await {
|
match stream.read_buf(&mut tmp).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) if err.kind() == io::ErrorKind::ConnectionReset => return Ok(None),
|
Err(err) if err.kind() == io::ErrorKind::ConnectionReset => return Ok(None),
|
||||||
@ -351,7 +354,7 @@ pub async fn read_packet(
|
|||||||
// Keep reading until we have all packet bytes
|
// Keep reading until we have all packet bytes
|
||||||
while buf.len() < consumed + len as usize {
|
while buf.len() < consumed + len as usize {
|
||||||
// Read packet from socket
|
// Read packet from socket
|
||||||
let mut tmp = Vec::with_capacity(64);
|
let mut tmp = Vec::with_capacity(BUF_SIZE);
|
||||||
match stream.read_buf(&mut tmp).await {
|
match stream.read_buf(&mut tmp).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) if err.kind() == io::ErrorKind::ConnectionReset => return Ok(None),
|
Err(err) if err.kind() == io::ErrorKind::ConnectionReset => return Ok(None),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user