updated monitoring socket
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-05-07 10:46:08 +02:00
parent df9d19f616
commit 43d3137dd2

View File

@ -24,34 +24,26 @@ pub async fn apiserver(ctxarc: &Arc<RwLock<Context>>) -> io::Result<()> {
loop { loop {
//apitx.send(String::from("")).await.unwrap(); //apitx.send(String::from("")).await.unwrap();
match listener.accept().await { match listener.accept().await {
Ok((stream, _addr)) => { Ok((mut stream, _addr)) => {
//let mut buf = [0; 1024]; //let mut buf = [0; 1024];
let data; let data;
{ {
let ctx = ctxarc.read().await; let ctx = ctxarc.read().await;
data = serde_json::to_string(&ctx.blocklist); data = serde_json::to_string(&ctx.blocklist).unwrap();
} }
match data { stream
Ok(dt) => { .write_all(format!("{data}\n").as_bytes())
let (_reader, mut writer) = stream.into_split(); .await
match writer.write_all(format!("{dt}").as_bytes()).await { .unwrap();
Ok(_) => {} stream.flush().await.unwrap();
Err(err) => { stream.shutdown().await.unwrap();
println!("{err}");
}
}
} }
Err(err) => { Err(err) => {
println!("unable to serialize data: {err}"); println!("unable to serialize data: {err}");
} }
} }
} }
Err(err) => {
println!("couldn't get client: {}", err)
}
}
}
}); });
Ok(()) Ok(())
} }