Skip to main content

DtactUnixStream

Struct DtactUnixStream 

Source
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

Source

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).

Source

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.

Source

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).

Source

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).

Source

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).

Trait Implementations§

Source§

impl AsyncRead for DtactUnixStream

Source§

async fn read(&self, buf: &mut [u8]) -> Result<usize>

Read into buf, returning the number of bytes read (0 = EOF). Read more
Source§

impl AsyncWrite for DtactUnixStream

Source§

async fn write(&self, buf: &[u8]) -> Result<usize>

Write from buf, returning the number of bytes written. Read more
Source§

impl Drop for DtactUnixStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.