Files
zesdex/src/ipc/server.rs
T
asepharyana 29a9fae3f6 ci: add GitHub Actions workflows with semantic-release auto-versioning
chore: fix all 702 clippy warnings across codebase
- auto-fix 475 via cargo clippy --fix
- fix remaining 227 manually: uninlined_format_args, redundant_closure, match_same_arms,
  underscore_binding, format_push_string, items_after_statements, needless_pass_by_value,
  clone_on_copy, case_sensitive_extension, single_match/let-else, write_with_newline,
  and other clippy lints
2026-07-13 08:12:12 +07:00

36 lines
1.2 KiB
Rust

//! Unix-socket listener for the `--daemon` process.
//!
//! Flow: `IpcServer::bind_unix` opens/binds a Unix socket at a well-known
//! path (clearing any stale file left by a crashed prior daemon) →
//! `accept` blocks for the next client and wraps it as a `Connection`
//! (see `conn.rs`) for framed request/response traffic.
use std::os::unix::net::UnixListener;
use anyhow::Result;
use super::conn::Connection;
/// Server-side handle for the `--daemon` process: listens on a Unix
/// socket and hands out `Connection`s to accepted clients.
pub struct IpcServer {
listener: UnixListener,
}
impl IpcServer {
/// Bind a new Unix-socket listener at `path`.
///
/// Why: removes any stale socket file at `path` first, since a prior
/// crashed daemon can leave one behind and `UnixListener::bind` fails
/// on an existing path.
pub fn bind_unix(path: &str) -> Result<Self> {
let _ = std::fs::remove_file(path);
let listener = UnixListener::bind(path)?;
Ok(IpcServer { listener })
}
/// Block until a client connects, then wrap it as a `Connection`.
pub fn accept(&self) -> Result<Connection> {
let (stream, _addr) = self.listener.accept()?;
Ok(Connection::from_stream(stream))
}
}