Skip to content

Commit

Permalink
session count on server
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed May 15, 2024
1 parent a9f748c commit f1c82ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ nginx_signing.key
overtls-daemon.sh
project.xcworkspace/
xcuserdata/
.vs/
.vscode/
.VSCodeCounter/
.env
Expand Down
8 changes: 8 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub async fn run_server(config: &Config, exiting_flag: crate::CancellationToken)
}
};

let session_count = Arc::new(std::sync::atomic::AtomicUsize::new(0));

loop {
tokio::select! {
_ = exiting_flag.cancelled() => {
Expand All @@ -105,10 +107,16 @@ pub async fn run_server(config: &Config, exiting_flag: crate::CancellationToken)
Ok::<_, Error>(())
};

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!("{}: {} sessions", 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!("{}: {} sessions", peer_addr, count);
});
}
}
Expand Down

0 comments on commit f1c82ff

Please sign in to comment.