aquatic_udp: mio: rewrite connection cleaning interval logic

This commit is contained in:
Joakim Frostegård 2021-10-31 21:12:52 +01:00
parent 03a344eb8e
commit 1949ed2e9c

View file

@ -53,7 +53,7 @@ pub fn run_socket_worker(
let timeout = Duration::from_millis(50); let timeout = Duration::from_millis(50);
let mut iter_counter = 0usize; let mut iter_counter = 0usize;
let mut now = Instant::now(); let mut last_cleaning = Instant::now();
loop { loop {
poll.poll(&mut events, Some(timeout)) poll.poll(&mut events, Some(timeout))
@ -86,10 +86,12 @@ pub fn run_socket_worker(
); );
if iter_counter % 32 == 0 { if iter_counter % 32 == 0 {
if now.elapsed().as_secs() >= config.cleaning.interval { let now = Instant::now();
if last_cleaning + Duration::from_secs(config.cleaning.interval) > now {
connections.clean(); connections.clean();
now = Instant::now(); last_cleaning = now;
} }
} }