add counter to keep track of connected clients

This commit is contained in:
Noa Aarts 2024-12-12 15:09:45 +01:00
parent c050d8bfb0
commit 3520118336
Signed by: noa
GPG key ID: 1850932741EFF672
2 changed files with 5 additions and 5 deletions

View file

@ -21,6 +21,7 @@ pub type Canvas = u8;
pub type Coordinate = u16;
pub static COUNTER: AtomicU64 = AtomicU64::new(0);
pub static CLIENTS: AtomicU64 = AtomicU64::new(0);
pub type AsyncResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;

View file

@ -12,7 +12,7 @@ use flurry::{
flutclient::{FlutClient, ParserTypes},
grid::{self, Flut},
webapi::WebApiContext,
AsyncResult,
AsyncResult, CLIENTS,
};
use futures::never::Never;
use tokio::{net::TcpListener, time::interval, try_join};
@ -59,11 +59,10 @@ async fn handle_flut(
handles.push(tokio::spawn(async move {
let (reader, writer) = socket.split();
let mut connection = FlutClient::new(reader, writer, grids);
CLIENTS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let resp = connection.process_socket().await;
match resp {
Ok(()) => Ok(()),
Err(err) => Err(err),
}
CLIENTS.fetch_sub(1, std::sync::atomic::Ordering::Relaxed);
resp
}))
}
}