chiark / gitweb /
actually expire old clients
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 14 Oct 2020 01:12:00 +0000 (02:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 14 Oct 2020 01:12:00 +0000 (02:12 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/daemon-otter.rs
src/global.rs
src/imports.rs

index 3df9167ee07459373fb0965e74d5b74ff63568bc..27e450a2f593edd1fb4e125ee2add04b294aa261 100644 (file)
@@ -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();
 }
index cc6c835806feaa8399353835fe4a7da6cc89ab43..4c714726d1d77c52d7199b1cdc604cb214b811d7 100644 (file)
@@ -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<InstanceContainer> {
     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";
index 9f7e935c362ff407383eee017d8e09d96eba27d4..155adc52c959ccbf1db2d5f1ab59f9d25f5c79fa 100644 (file)
@@ -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};