From 6fa55cdc614cc080ec200ba0ef876d33e6277692 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 4 Oct 2023 11:23:14 +0200 Subject: [PATCH] code cleanup --- src/main.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 785d9da..f9e39f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,6 +95,7 @@ fn mopp(speed: u8, data: &[u8]) -> Vec { ); let mut res = Vec::::new(); + for i in (0..m.len()).step_by(8) { let value = u8::from_str_radix(&m[i..i + 8], 2).unwrap(); res.push(value); @@ -118,24 +119,23 @@ fn broadcast( } } -fn remove_old_clients(socket: &UdpSocket, - subscribers: &mut HashMap>,) { - let timestamp = Local::now(); +fn remove_old_clients(socket: &UdpSocket, subscribers: &mut HashMap>) { + let timestamp = Local::now(); - debug!("Number of clients: {}", subscribers.len()); + debug!("Number of clients: {}", subscribers.len()); - for cl in &*subscribers { - if *cl.1 + Duration::seconds(CLIENT_TIMEOUT as i64) < timestamp { - debug!("Removing old client {}", cl.0); - socket - .send_to(mopp(MY_SPEED, b":bye").as_slice(), &cl.0) - .unwrap(); - } + for cl in &*subscribers { + if *cl.1 + Duration::seconds(CLIENT_TIMEOUT as i64) < timestamp { + debug!("Removing old client {}", cl.0); + socket + .send_to(mopp(MY_SPEED, b":bye").as_slice(), &cl.0) + .unwrap(); } - - subscribers.retain(|_, val| *val + Duration::seconds(CLIENT_TIMEOUT as i64) >= timestamp); } + subscribers.retain(|_, val| *val + Duration::seconds(CLIENT_TIMEOUT as i64) >= timestamp); +} + fn main() -> std::io::Result<()> { env_logger::init(); @@ -204,6 +204,6 @@ fn main() -> std::io::Result<()> { debug!("Ignoring unknown client {client_addr}"); } - remove_old_clients(&socket, &mut subscribers); + remove_old_clients(&socket, &mut subscribers); } }