nzrd: actually serve the events

This commit is contained in:
snow flurry 2024-08-18 20:33:33 -07:00
parent f1dd375e2f
commit f0772b10e2
2 changed files with 27 additions and 2 deletions

14
nzrd/src/event.rs Normal file
View file

@ -0,0 +1,14 @@
use std::io;
use tokio::net::UnixListener;
use crate::ctx::Context;
pub async fn event_server(ctx: Context) -> io::Result<()> {
let sock = UnixListener::bind(&ctx.config.rpc.events_sock)?;
loop {
let (client, addr) = sock.accept().await?;
ctx.events.spawn(client, addr).await?;
}
}

View file

@ -1,6 +1,7 @@
mod cmd;
mod ctrl;
mod ctx;
mod event;
mod model;
mod rpc;
@ -25,8 +26,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing::warn!("Couldn't parse log level from config, defaulting to {log_level}");
}
if let Err(err) = rpc::serve(ctx.clone()).await {
tracing::error!("Error from RPC: {}", err);
// Run both the RPC and events servers
tokio::select! {
res = rpc::serve(ctx.clone()) => {
if let Err(err) = res {
tracing::error!("RPC server error: {err}");
}
},
res = event::event_server(ctx.clone()) => {
if let Err(err) = res {
tracing::error!("Event server error: {err}");
}
}
}
Ok(())