put the sleep at the loop start

This commit is contained in:
Martin Brodbeck 2023-10-05 07:57:48 +02:00
parent 4afab41abe
commit 233f70af28

View file

@ -149,6 +149,8 @@ fn main() -> std::io::Result<()> {
let mut subscribers: HashMap<String, DateTime<Local>> = HashMap::new();
loop {
thread::sleep(core::time::Duration::from_millis(200)); // Anti flood (?)
let mut buf = [0; 64];
// Waiting for incoming pakets. Otherwise, after timeout, send keepalive paket
@ -157,7 +159,7 @@ fn main() -> std::io::Result<()> {
Ok((num, s)) => (num, s),
Err(_) => {
remove_old_clients(&socket, &mut subscribers);
// debug!("Sending keepalive pakets …");
for rec in &subscribers {
debug!("Sending keepalive paket to {}", rec.0);
socket.send_to(b"", rec.0).unwrap();
@ -170,8 +172,6 @@ fn main() -> std::io::Result<()> {
let speed = buf[1] >> 2;
let data = &buf[0..number_of_bytes];
thread::sleep(core::time::Duration::from_millis(200)); // Anti flood (?)
if subscribers.contains_key(&client_addr) {
debug!("Client known: {client_addr}");