fix: dont freak out when client loses connection

This commit is contained in:
2026-08-16 17:53:42 +02:00
parent 59884919a6
commit 71105d9783
3 changed files with 18 additions and 0 deletions

View File

@@ -22,6 +22,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
break;
}
if buffer == "/test\n" {
buffer = String::from("A").repeat(1024 * 1024 * 2);
}
client.send_text_message(buffer.clone()).await;
buffer.clear();
}

View File

@@ -87,6 +87,9 @@ impl Client {
ServerMessage::BroadcastCurrentTurn { active_player } => todo!(),
ServerMessage::GameEnd { result } => todo!(),
}
} else {
error!("Connection broken");
break;
}
}
});

View File

@@ -162,6 +162,17 @@ where
}
async fn read_content(&mut self, size_to_read: u32) -> Result<(), io::Error> {
let max_size = 1024 * 1024 * 2;
if size_to_read > max_size {
error!(
"Message sent exeeds the limit. Sent {}, max: {}",
size_to_read, max_size
);
self.tcp = None;
return Err(io::ErrorKind::InvalidData.into());
}
let mut buff: Vec<u8> = vec![0; size_to_read as usize];
let Some(tcp) = &mut self.tcp else {