put the sleep at the loop start
This commit is contained in:
parent
4afab41abe
commit
233f70af28
1 changed files with 5 additions and 5 deletions
10
src/main.rs
10
src/main.rs
|
@ -95,7 +95,7 @@ fn mopp(speed: u8, data: &[u8]) -> Vec<u8> {
|
|||
);
|
||||
|
||||
let mut res = Vec::<u8>::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);
|
||||
|
@ -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,11 +172,9 @@ 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}");
|
||||
|
||||
|
||||
if strip_header(data) == strip_header(mopp(speed, b":bye").as_slice()) {
|
||||
debug!("Removing client {client_addr} as requested.");
|
||||
socket
|
||||
|
|
Loading…
Reference in a new issue