feat: Initial accept loop

This commit is contained in:
selfhoster selfhoster 2026-09-01 15:27:28 +02:00
commit d30df04064
10 changed files with 1764 additions and 0 deletions

42
src/main.rs Normal file
View file

@ -0,0 +1,42 @@
// #![deny(warnings)]
mod cli;
mod error;
mod listener;
mod stream;
use cli::CliArgs;
use error::GlobalError;
use listener::ListenerPath;
use stream::AbstractStream;
#[tracing::instrument(name = "client", skip(s), fields(session = %s.session))]
async fn client(s: AbstractStream) {
tracing::info! {
remote_addr = ?s.remote_addr,
"New client connection"
};
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), GlobalError> {
let cli: CliArgs = argh::from_env();
tracing_subscriber::fmt::init();
// let subscriber = tracing_subscriber::FmtSubscriber::new();
// .with_file(true)
// .with_line_number(true)
// .finish()
// .init();
// tracing::subscriber::set_global_default(subscriber)?;
let listener = ListenerPath::new(&cli.listen)?.listener().await?;
// If the connection is None, it's because the client aborted early
// so there's nothing to do about it.
while let Some(stream) = listener.accept().await? {
client(stream).await;
}
Ok(())
}