Skip to main content

DtactUnixDatagram

Struct DtactUnixDatagram 

Source
pub struct DtactUnixDatagram { /* private fields */ }
Expand description

Async Unix-domain datagram socket.

Connectionless counterpart to DtactUnixStream, directly analogous to DtactUdpSocket (same connectionless send_to/recv_from and connected connect/send/recv pattern, same SendTo/RecvFrom/ Read/Write submission machinery — only the address family and the libc::sockaddr_un construction differ).

Implementations§

Source§

impl DtactUnixDatagram

Source

pub fn bind(path: impl AsRef<Path>) -> Result<Self>

Bind a new datagram socket to the filesystem path path and register it with the driver. path must not already exist — like std::os::unix::net::UnixDatagram::bind, this does not remove a stale socket file left behind by a previous run.

§Errors

Returns any error from binding the OS socket or registering it.

Source

pub fn unbound() -> Result<Self>

Create an unbound datagram socket (matches std::os::unix::net::UnixDatagram::unbound) — usable for send_to/connect immediately, has no path of its own until (if ever) explicitly bound.

§Errors

Returns any error from creating the OS socket or registering it.

Source

pub fn from_std(socket: UnixDatagram) -> Result<Self>

Register an existing std::os::unix::net::UnixDatagram, taking ownership.

§Errors

Returns any error from switching the socket to non-blocking mode or registering it with the driver.

§Panics

Panics if called before init_runtime/init has been called (WORKERS not yet initialized).

Source

pub async fn send_to( &self, buf: &[u8], target: impl AsRef<Path>, ) -> Result<usize>

Send buf as a single datagram to the socket bound at target, returning the number of bytes sent.

§Errors

Returns any error from the underlying sendmsg, target path resolution included (e.g. too long for sockaddr_un::sun_path).

Source

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

Receive a single datagram into buf, returning the byte count and the peer address it came from.

§Errors

Returns any error from the underlying recvmsg.

Source

pub async fn connect(&self, target: impl AsRef<Path>) -> Result<()>

Connect this socket to the path target so send/recv can omit the peer address.

§Errors

Returns any error from the underlying connect.

Source

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

Send buf to the connected peer, returning the number of bytes sent.

§Errors

Returns any error from the underlying send.

Source

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

Receive a datagram from the connected peer into buf, returning the byte count.

§Errors

Returns any error from the underlying recv.

Trait Implementations§

Source§

impl Drop for DtactUnixDatagram

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.