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 b84586d
Show file tree
Hide file tree
Showing 2 changed files with 11 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
10 changes: 10 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand All @@ -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);
});
}
}
Expand Down

0 comments on commit b84586d

Please sign in to comment.