From b84586dfb5244941d6b82c9c184b914f4a16e155 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Wed, 15 May 2024 14:45:18 +0800 Subject: [PATCH] session count on server --- .gitignore | 1 + src/server.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 6288446..0aa4f14 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ nginx_signing.key overtls-daemon.sh project.xcworkspace/ xcuserdata/ +.vs/ .vscode/ .VSCodeCounter/ .env diff --git a/src/server.rs b/src/server.rs index 6113a69..d7a502b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -83,6 +83,9 @@ pub async fn run_server(config: &Config, exiting_flag: crate::CancellationToken) } }; + let session_id = Arc::new(std::sync::atomic::AtomicUsize::new(0)); + let session_count = Arc::new(std::sync::atomic::AtomicUsize::new(0)); + loop { tokio::select! { _ = exiting_flag.cancelled() => { @@ -105,10 +108,17 @@ pub async fn run_server(config: &Config, exiting_flag: crate::CancellationToken) Ok::<_, Error>(()) }; + let session_id = session_id.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + let session_count = session_count.clone(); + tokio::spawn(async move { + let count = session_count.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + 1; + log::debug!("session #{} from {} started, session count {}", session_id, peer_addr, count); if let Err(e) = incoming_task.await { log::debug!("{peer_addr}: {e}"); } + let count = session_count.fetch_sub(1, std::sync::atomic::Ordering::SeqCst) - 1; + log::debug!("session #{} from {} ended, session count {}", session_id, peer_addr, count); }); } }