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
impl DtactUnixDatagram
Sourcepub fn bind(path: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn unbound() -> Result<Self>
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.
Sourcepub fn from_std(socket: UnixDatagram) -> Result<Self>
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).
Sourcepub async fn send_to(
&self,
buf: &[u8],
target: impl AsRef<Path>,
) -> Result<usize>
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).
Sourcepub async fn recv_from(
&self,
buf: &mut [u8],
) -> Result<(usize, DtactUnixSocketAddr)>
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.