docs: docs for UDS data client/server (#57)
Signed-off-by: STRRL <im@strrl.dev>
This commit is contained in:
parent
5f6b967fde
commit
d2aacf8e03
|
@ -4,6 +4,14 @@ use tokio::io::AsyncWriteExt;
|
|||
use tokio::net::UnixListener;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
/// UdsDataServer is designed **ONLY** for communicate between chaos-tproxy main process and chaos-tproxy child process.
|
||||
/// It's not a general purpose Unix Domain Socket server.
|
||||
///
|
||||
/// UdsDataServer would listen to certain path, and waiting for the connection from chaos-tproxy child process. Once the
|
||||
/// client connect, it would send the serialized data to the client immediately.
|
||||
///
|
||||
/// See [chaos_tproxy_proxy::uds_client::UdsDataClient] for opposite side logics.
|
||||
pub struct UdsDataServer<T> {
|
||||
pub data: T,
|
||||
pub path: PathBuf,
|
||||
|
@ -25,6 +33,11 @@ impl<T: serde::ser::Serialize> UdsDataServer<T> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// listen would listen on the target Unix Domain Socket path, and waiting for the connection from chaos-tproxy,
|
||||
/// child, once the client connect, it would send the serialized data to the client immediately.
|
||||
///
|
||||
/// It would block the current thread, so it's recommended to call this method in a new thread.
|
||||
/// TODO(@STRRL): graceful shutdown is not supported yet
|
||||
pub async fn listen(&self, listener: UnixListener) -> anyhow::Result<()> {
|
||||
tracing::info!("Uds listener listening on {:?}", &self.path);
|
||||
loop {
|
||||
|
|
|
@ -3,6 +3,11 @@ use std::path::PathBuf;
|
|||
use tokio::io::AsyncReadExt;
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
/// UdsDataClient is designed **ONLY** for communicate between chaos-tproxy main process and chaos-tproxy child process.
|
||||
/// It's not a general purpose Unix Domain Socket client.
|
||||
///
|
||||
/// UdsDataClient would create a connection to a certain Unix Domain Socket, and read the serialized data from that
|
||||
/// socket, then try to deserialize data to the required type.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UdsDataClient {
|
||||
pub path: PathBuf,
|
||||
|
@ -13,6 +18,10 @@ impl UdsDataClient {
|
|||
Self { path }
|
||||
}
|
||||
|
||||
/// read_into would create a new connection to the target Unix Domain Socket and receive the serialized data from
|
||||
/// server-side, then try to deserialize data to the required type.
|
||||
///
|
||||
/// It would establish a new connection every time, so it's safe to call this method multiple times.
|
||||
pub async fn read_into<'a, T: serde::de::Deserialize<'a>>(
|
||||
&self,
|
||||
buf: &'a mut Vec<u8>,
|
||||
|
|
Loading…
Reference in New Issue