diff --git a/chaos-tproxy-controller/src/proxy/uds_server.rs b/chaos-tproxy-controller/src/proxy/uds_server.rs index d811ca8..02ee1a9 100644 --- a/chaos-tproxy-controller/src/proxy/uds_server.rs +++ b/chaos-tproxy-controller/src/proxy/uds_server.rs @@ -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 { pub data: T, pub path: PathBuf, @@ -25,6 +33,11 @@ impl UdsDataServer { 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 { diff --git a/chaos-tproxy-proxy/src/uds_client.rs b/chaos-tproxy-proxy/src/uds_client.rs index 63cfa5e..c200e27 100644 --- a/chaos-tproxy-proxy/src/uds_client.rs +++ b/chaos-tproxy-proxy/src/uds_client.rs @@ -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,