basic logging

This commit is contained in:
2025-06-16 18:11:48 +02:00
parent 10837dac35
commit 39dd27378a
5 changed files with 223 additions and 10 deletions

View File

@@ -17,15 +17,9 @@ pub struct Server {
}
impl Server {
pub const MAX_CONNECTIONS: usize = 256;
pub async fn new(config: ServerConfig) -> Result<Self> {
pub async fn new(config: &ServerConfig) -> Result<Self> {
let addr = format!("{}:{}", config.host, config.port);
Self::_new(
addr,
config.max_connections.unwrap_or(Self::MAX_CONNECTIONS),
)
.await
Self::_new(addr, config.max_connections).await
}
async fn _new<Addr: ToSocketAddrs>(addr: Addr, max_connections: usize) -> Result<Self> {
@@ -46,14 +40,17 @@ impl Server {
.unwrap();
let socket = self.listener.accept().await?.0;
let addr = socket.peer_addr()?;
let connection = Connection::new(socket);
let mut handler = Handler::new(self.db.clone(), connection);
tokio::spawn(async move {
log::debug!("Spawned a new connection handler: {addr}");
if let Err(e) = handler.run().await {
println!("Handler::run error: {e:?}");
}
log::debug!("Connection handler ended: {addr}");
drop(permit);
});