Improve terminal input and client cleanup
ci / test (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
Codex
2026-06-11 14:32:55 -04:00
parent 14cdd5fd56
commit 2257aeca0b
3 changed files with 168 additions and 18 deletions
+20
View File
@@ -125,6 +125,15 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
}
});
let cleanup_state = Arc::clone(&state);
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(5));
loop {
interval.tick().await;
cleanup_disconnected_clients(&cleanup_state);
}
});
let mut buf = vec![0u8; 65535];
loop {
let (n, peer) = socket.recv_from(&mut buf).await?;
@@ -781,6 +790,17 @@ async fn retransmit_pending(
Ok(())
}
fn cleanup_disconnected_clients(state: &Arc<Mutex<ServerState>>) {
let mut locked = state.lock().expect("server state poisoned");
let timeout = Duration::from_secs(locked.config.client_timeout_secs.max(1));
let now = Instant::now();
for session in locked.sessions.values_mut() {
session
.clients
.retain(|_, client| now.duration_since(client.last_seen) <= timeout);
}
}
fn find_client_key(
state: &Arc<Mutex<ServerState>>,
client_id: &[u8; 16],