pub struct DtactUnixStream { /* private fields */ }Expand description
A lock-free, non-blocking Unix-domain-socket stream registered with
the dtact-io driver. Mirrors DtactTcpStream’s API.
Implementations§
Source§impl DtactUnixStream
impl DtactUnixStream
Sourcepub fn from_std(stream: UnixStream) -> Result<Self>
pub fn from_std(stream: UnixStream) -> Result<Self>
Register an existing non-blocking UnixStream with the dtact-io
driver. See DtactTcpStream::from_std for the registration
mechanics (identical here, minus the TCP_NODELAY call — Unix
domain sockets have nothing analogous to disable).
§Errors
Returns an io::Error if set_nonblocking fails.
§Panics
Panics if called before init_runtime/init has been called
(WORKERS not yet initialized).
Sourcepub async fn read(&self, buf: &mut [u8]) -> Result<usize>
pub async fn read(&self, buf: &mut [u8]) -> Result<usize>
Read into buf, returning Ok(0) immediately for an empty buffer
without issuing a syscall. See DtactTcpStream::read for the
fast-path-syscall-before-going-async rationale (identical here).
§Errors
Returns an io::Error if the underlying read reports one; Ok(0)
signals EOF, not an error.
Sourcepub async fn write(&self, buf: &[u8]) -> Result<usize>
pub async fn write(&self, buf: &[u8]) -> Result<usize>
Write buf, returning Ok(0) immediately for an empty buffer
without issuing a syscall. See DtactTcpStream::write for the
fast-path rationale (identical here).
§Errors
Returns an io::Error if the underlying write reports one (e.g.
BrokenPipe if the peer closed the connection).
Sourcepub async fn connect(path: impl AsRef<Path>) -> Result<Self>
pub async fn connect(path: impl AsRef<Path>) -> Result<Self>
Create a new non-blocking Unix domain socket and connect to the
filesystem path path, registering the result with the dtact-io
driver. See DtactTcpStream::connect for the direct-connect /
EINPROGRESS / async-fallback sequencing (identical here, modulo
address family).
§Errors
Returns an io::Error if socket creation, set_nonblocking, the
connect(2) syscall (or its io_uring completion), or path
itself (e.g. too long for sockaddr_un::sun_path) fails — e.g.
ConnectionRefused/NotFound if nothing is listening at path.
§Panics
Panics if called before init_runtime/init has been called
(WORKERS not yet initialized).
Sourcepub fn peer_cred(&self) -> Result<DtactUCred>
pub fn peer_cred(&self) -> Result<DtactUCred>
The connected peer’s credentials (PID/UID/GID), as recorded by the
kernel at connect(2)/accept(2) time — not queryable/spoofable
after the fact by the peer itself, which is what makes this useful
for authorization over a local socket.
A plain synchronous syscall (getsockopt(SO_PEERCRED) on Linux,
getpeereid(2) elsewhere), not routed through the driver — same
“cheap enough to not need the ring” judgment call as
DtactTcpStream’s local_addr-shaped helpers.
§Errors
Returns an io::Error if the underlying syscall fails (e.g. the
socket was closed concurrently).