Fixed bad event cycle poisoning issue

This commit is contained in:
Arthur Beck 2025-03-20 12:57:00 +00:00
parent ffbbabbddb
commit 58fd728dbf

View file

@ -198,34 +198,39 @@ fn handle_client(mut stream: TcpStream, channel: Channel) {
let mut current_message_count = channel.lock().unwrap().messages.len();
loop {
if recieve_terminate_recv.try_recv().is_ok() {
stream.shutdown(std::net::Shutdown::Both).unwrap();
let _ = stream.shutdown(std::net::Shutdown::Both);
panic!("recieve thread exiting");
}
#[warn(clippy::panic, clippy::unwrap_used)]
{
#[allow(clippy::unwrap_used)]
let lock = channel.lock().unwrap();
let new_message_count = lock.messages.len();
if current_message_count != new_message_count {
let new_messages = &lock.messages[current_message_count..];
for msg in new_messages {
if !msg.me_message {
stream
if stream
.write_fmt(format_args!(
"\x1b[0m\x1b[34m[{}]\x1b[0m \x1b[1m{}\x1b[0m \x1b[31m⇛\x1b[0m \x1b[35m{}\x1b[0m\n",
msg.timestamp.format(&time_format).unwrap(),
msg.timestamp.format(&time_format).expect("the time is evil"),
msg.sender.name,
msg.contents
))
.unwrap();
} else {
stream
.is_err() {
break;
}
} else if stream
.write_fmt(format_args!(
"\x1b[0m\x1b[34m[{}]\x1b[0m \x1b[1;3m{}\x1b[0m \x1b[3m{}\x1b[0m\n",
msg.timestamp.format(&time_format).unwrap(),
msg.timestamp.format(&time_format).expect("the time is evil"),
msg.sender.name,
msg.contents
))
.unwrap();
}
.is_err() {
break;
}
}
current_message_count = new_message_count;