//! IPC client — connects to the daemon's Unix socket and sends/receives //! framed JSON messages. use std::os::unix::net::UnixStream; use std::sync::Mutex; /// A thread-safe IPC client connected to a Zesdex daemon over a Unix socket. pub struct IpcClient { conn: Mutex, } impl IpcClient { pub fn connect_unix(path: &str) -> anyhow::Result { let stream = UnixStream::connect(path)?; let conn = crate::ipc::conn::Connection::new(stream); Ok(Self { conn: Mutex::new(conn), }) } pub fn send(&self, msg: &T) -> anyhow::Result<()> { let mut guard = self .conn .lock() .expect("IpcClient mutex poisoned"); guard.send(msg) } pub fn receive(&self) -> anyhow::Result> { let mut guard = self .conn .lock() .expect("IpcClient mutex poisoned"); guard.receive() } }