2026-07-11 20:21:59 +07:00
|
|
|
use std::os::unix::net::UnixListener;
|
2026-07-11 13:16:10 +07:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use super::conn::Connection;
|
|
|
|
|
|
|
|
|
|
pub struct IpcServer {
|
2026-07-11 23:45:13 +07:00
|
|
|
listener: UnixListener,
|
2026-07-11 13:16:10 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl IpcServer {
|
2026-07-11 20:21:59 +07:00
|
|
|
pub fn bind_unix(path: &str) -> Result<Self> {
|
|
|
|
|
let _ = std::fs::remove_file(path);
|
|
|
|
|
let listener = UnixListener::bind(path)?;
|
2026-07-11 23:45:13 +07:00
|
|
|
Ok(IpcServer { listener })
|
2026-07-11 13:16:10 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn accept(&self) -> Result<Connection> {
|
2026-07-11 23:45:13 +07:00
|
|
|
let (stream, _addr) = self.listener.accept()?;
|
|
|
|
|
Connection::from_stream(stream)
|
2026-07-11 13:16:10 +07:00
|
|
|
}
|
|
|
|
|
}
|