42 lines
1 KiB
Rust
42 lines
1 KiB
Rust
|
|
// #![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(())
|
||
|
|
}
|