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();
|
let mut res = Vec::<u8>::new();
|
||||||
|
|
||||||
for i in (0..m.len()).step_by(8) {
|
for i in (0..m.len()).step_by(8) {
|
||||||
let value = u8::from_str_radix(&m[i..i + 8], 2).unwrap();
|
let value = u8::from_str_radix(&m[i..i + 8], 2).unwrap();
|
||||||
res.push(value);
|
res.push(value);
|
||||||
|
@ -149,6 +149,8 @@ fn main() -> std::io::Result<()> {
|
||||||
let mut subscribers: HashMap<String, DateTime<Local>> = HashMap::new();
|
let mut subscribers: HashMap<String, DateTime<Local>> = HashMap::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
thread::sleep(core::time::Duration::from_millis(200)); // Anti flood (?)
|
||||||
|
|
||||||
let mut buf = [0; 64];
|
let mut buf = [0; 64];
|
||||||
|
|
||||||
// Waiting for incoming pakets. Otherwise, after timeout, send keepalive paket
|
// Waiting for incoming pakets. Otherwise, after timeout, send keepalive paket
|
||||||
|
@ -157,7 +159,7 @@ fn main() -> std::io::Result<()> {
|
||||||
Ok((num, s)) => (num, s),
|
Ok((num, s)) => (num, s),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
remove_old_clients(&socket, &mut subscribers);
|
remove_old_clients(&socket, &mut subscribers);
|
||||||
// debug!("Sending keepalive pakets …");
|
|
||||||
for rec in &subscribers {
|
for rec in &subscribers {
|
||||||
debug!("Sending keepalive paket to {}", rec.0);
|
debug!("Sending keepalive paket to {}", rec.0);
|
||||||
socket.send_to(b"", rec.0).unwrap();
|
socket.send_to(b"", rec.0).unwrap();
|
||||||
|
@ -170,11 +172,9 @@ fn main() -> std::io::Result<()> {
|
||||||
let speed = buf[1] >> 2;
|
let speed = buf[1] >> 2;
|
||||||
let data = &buf[0..number_of_bytes];
|
let data = &buf[0..number_of_bytes];
|
||||||
|
|
||||||
thread::sleep(core::time::Duration::from_millis(200)); // Anti flood (?)
|
|
||||||
|
|
||||||
if subscribers.contains_key(&client_addr) {
|
if subscribers.contains_key(&client_addr) {
|
||||||
debug!("Client known: {client_addr}");
|
debug!("Client known: {client_addr}");
|
||||||
|
|
||||||
if strip_header(data) == strip_header(mopp(speed, b":bye").as_slice()) {
|
if strip_header(data) == strip_header(mopp(speed, b":bye").as_slice()) {
|
||||||
debug!("Removing client {client_addr} as requested.");
|
debug!("Removing client {client_addr} as requested.");
|
||||||
socket
|
socket
|
||||||
|
|
Loading…
Reference in a new issue