sleep for shorter intervals between each ping

This commit is contained in:
Nils Andreas Svee committed 2023-03-01 20:13:46 +01:00
1 parent 7134f62e02
commit 7a589ffdf7
1 file changed
+3 -3
+3 -3
View File
@@ -122,12 +122,13 @@ pub trait PingSender {
let mut seq: u16 = 0; let mut seq: u16 = 0;
let tick_duration_ms: u16 = 500; let tick_duration_ms: u16 = 500;
let sleep_duration = Duration::from_millis(tick_duration_ms as u64);
loop { loop {
let reflectors_unlocked = reflectors_lock.read().unwrap(); let reflectors_unlocked = reflectors_lock.read().unwrap();
let reflectors = reflectors_unlocked.clone(); let reflectors = reflectors_unlocked.clone();
drop(reflectors_unlocked); drop(reflectors_unlocked);
let sleep_duration =
Duration::from_millis((tick_duration_ms / reflectors.len() as u16) as u64);
for reflector in reflectors.iter() { for reflector in reflectors.iter() {
let addr: SockAddr = match reflector.is_ipv4() { let addr: SockAddr = match reflector.is_ipv4() {
@@ -147,10 +148,9 @@ pub trait PingSender {
let buf = buf_v.as_slice(); let buf = buf_v.as_slice();
socket.send_to(buf, &addr)?; socket.send_to(buf, &addr)?;
thread::sleep(sleep_duration);
} }
thread::sleep(sleep_duration);
if seq == u16::MAX { if seq == u16::MAX {
seq = 0; seq = 0;
} else { } else {