From 1988fa14e5136bee47e28c3a0314d506438ecea4 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 14 Oct 2020 02:12:00 +0100 Subject: [PATCH] actually expire old clients Signed-off-by: Ian Jackson --- src/bin/daemon-otter.rs | 3 +++ src/global.rs | 11 +++++++++-- src/imports.rs | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/bin/daemon-otter.rs b/src/bin/daemon-otter.rs index 3df9167e..27e450a2 100644 --- a/src/bin/daemon-otter.rs +++ b/src/bin/daemon-otter.rs @@ -175,5 +175,8 @@ fn main() { let r = otter::session::mount(r); let r = otter::api::mount(r); + + thread::spawn(client_periodic_expiry); + r.launch(); } diff --git a/src/global.rs b/src/global.rs index cc6c8358..4c714726 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1001,9 +1001,9 @@ pub fn game_flush_task() { } } -// ---------- client expiry ---------- xxx not working +// ---------- client expiry ---------- -pub fn client_expire_old_clients() { +fn client_expire_old_clients() { fn lock_even_poisoned(gref: &InstanceRef) -> MutexGuard { match gref.0.lock() { Ok(g) => g, @@ -1063,6 +1063,13 @@ pub fn client_expire_old_clients() { } } +pub fn client_periodic_expiry() { + loop { + sleep(MAX_CLIENT_INACTIVITY); + client_expire_old_clients(); + } +} + // ========== server config ========== const DEFAULT_CONFIG_FILENAME : &str = "server.toml"; diff --git a/src/imports.rs b/src/imports.rs index 9f7e935c..155adc52 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -8,7 +8,7 @@ pub use std::io::ErrorKind; pub use std::fmt::Write as _; pub use std::fmt::Formatter; pub use std::fmt::{self,Display,Debug}; -pub use std::thread; +pub use std::thread::{self,sleep}; pub use std::time::Duration; pub use std::sync::{Arc,Mutex,MutexGuard,RwLock,RwLockReadGuard,Condvar}; pub use std::collections::{HashMap,hash_map,HashSet}; -- 2.30.2