pub struct UnixDatagram { /* private fields */ }
Expand description

A Unix datagram socket.

After creating a UnixDatagram by binding it to a path, data can be sent to and received from any other socket address.

Cloning a UnixDatagram creates another handle to the same socket. The socket will be closed when all handles to it are dropped. The reading and writing portions of the socket can also be shut down individually with the shutdown() method.

Examples

use async_net::unix::UnixDatagram;

let socket = UnixDatagram::bind("/tmp/socket1")?;
socket.send_to(b"hello", "/tmp/socket2").await?;

let mut buf = vec![0u8; 1024];
let (n, addr) = socket.recv_from(&mut buf).await?;

Implementations

Creates a new UnixDatagram bound to the given address.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::bind("/tmp/socket")?;

Creates a Unix datagram socket not bound to any address.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::unbound()?;

Creates a pair of connected Unix datagram sockets.

Examples
use async_net::unix::UnixDatagram;

let (socket1, socket2) = UnixDatagram::pair()?;

Connects the Unix datagram socket to the given address.

When connected, methods send() and recv() will use the specified address for sending and receiving messages. Additionally, a filter will be applied to recv_from() so that it only receives messages from that same address.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::unbound()?;
socket.connect("/tmp/socket")?;

Returns the local address this socket is bound to.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::bind("/tmp/socket")?;
println!("Bound to {:?}", socket.local_addr()?);

Returns the remote address this socket is connected to.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::unbound()?;
socket.connect("/tmp/socket")?;
println!("Connected to {:?}", socket.peer_addr()?);

Receives data from an address.

On success, returns the number of bytes received and the address data came from.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::bind("/tmp/socket")?;

let mut buf = vec![0; 1024];
let (n, addr) = socket.recv_from(&mut buf).await?;
println!("Received {} bytes from {:?}", n, addr);

Sends data to the given address.

On success, returns the number of bytes sent.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::unbound()?;
socket.send_to(b"hello", "/tmp/socket").await?;

Receives data from the connected address.

On success, returns the number of bytes received.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::unbound()?;
socket.connect("/tmp/socket")?;

let mut buf = vec![0; 1024];
let n = socket.recv(&mut buf).await?;

Sends data to the connected address.

On success, returns the number of bytes sent.

Examples
use async_net::unix::UnixDatagram;

let socket = UnixDatagram::unbound()?;
socket.connect("/tmp/socket")?;
socket.send(b"hello").await?;

Shuts down the read half, write half, or both halves of this socket.

This method will cause all pending and future I/O in the given directions to return immediately with an appropriate value (see the documentation of Shutdown).

Examples
use async_net::{Shutdown, unix::UnixDatagram};

let socket = UnixDatagram::unbound()?;
socket.shutdown(Shutdown::Both)?;

Trait Implementations

Extracts the raw file descriptor. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.