docs: hagent

pull/7/head
prplV 2024-11-13 14:48:24 +03:00
parent d58f140a29
commit 15bb446aa4
1 changed files with 39 additions and 2 deletions

View File

@ -1,12 +1,37 @@
// module needed to check host-agent health condition and to communicate with it // module needed to check host-agent health condition and to communicate with it
/// asdasdasds
use tokio::{io::Interest, net::UnixStream}; use tokio::{io::Interest, net::UnixStream};
/// # Fn `open_unix_socket`
/// ## opening unix-socket for host-agent communication
///
/// *input* : -
///
/// *output* : `Ok(socket)` if socket was successfully opened | `Err(er)` if not
///
/// *initiator* : main thread `(??)`
///
/// *managing* : -
///
/// *depends on* : -
///
async fn open_unix_socket() -> Result<UnixStream, std::io::Error> { async fn open_unix_socket() -> Result<UnixStream, std::io::Error> {
let socket = UnixStream::connect("/var/run/enode/hostagent.sock").await?; let socket = UnixStream::connect("/var/run/enode/hostagent.sock").await?;
Ok(socket) Ok(socket)
} }
/// # Fn `ha_healthcheck`
/// ## for checking host-agent state
///
/// *input* : `&UnixStream`
///
/// *output* : `Ok(()))` if host-agent is running | `Err(er)` if not
///
/// *initiator* : main thread `(??)`
///
/// *managing* : ref on unix-socket object
///
/// *depends on* : -
///
async fn ha_healthcheck(socket: &UnixStream) -> Result<(), std::io::Error >{ async fn ha_healthcheck(socket: &UnixStream) -> Result<(), std::io::Error >{
socket.ready(Interest::WRITABLE).await?; socket.ready(Interest::WRITABLE).await?;
if socket.writable().await.is_ok() { if socket.writable().await.is_ok() {
@ -19,7 +44,19 @@ async fn ha_healthcheck(socket: &UnixStream) -> Result<(), std::io::Error >{
Ok(()) Ok(())
} }
/// # Fn `ha_healthcheck`
/// ## for sending data to host-agent using unix-socket
///
/// *input* : `&UnixStream`, `&str`
///
/// *output* : `Ok(()))` if data was sent| `Err(er)` if not
///
/// *initiator* : main thread `(??)`
///
/// *managing* : socket: `&UnixStream`, data: `&str`
///
/// *depends on* : -
///
async fn ha_send_data(socket: &UnixStream, data: &str) -> Result<(), std::io::Error > { async fn ha_send_data(socket: &UnixStream, data: &str) -> Result<(), std::io::Error > {
socket.ready(Interest::WRITABLE).await?; socket.ready(Interest::WRITABLE).await?;
if socket.writable().await.is_ok() { if socket.writable().await.is_ok() {