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

This type is an async version of std::os::unix::net::UnixDatagram.

Examples

use async_std::os::unix::net::UnixDatagram;

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

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

Implementations

Creates a Unix datagram socket bound to the given path.

Examples
use async_std::os::unix::net::UnixDatagram;

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

Creates a Unix datagram which is not bound to any address.

Examples
use async_std::os::unix::net::UnixDatagram;

let socket = UnixDatagram::unbound()?;

Creates an unnamed pair of connected sockets.

Returns two sockets which are connected to each other.

Examples
use async_std::os::unix::net::UnixDatagram;

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

Connects the socket to the specified address.

The send method may be used to send data to the specified address. recv and recv_from will only receive data from that address.

Examples
use async_std::os::unix::net::UnixDatagram;

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

Returns the address of this socket.

Examples
use async_std::os::unix::net::UnixDatagram;

let socket = UnixDatagram::bind("/tmp/socket").await?;
let addr = socket.local_addr()?;

Returns the address of this socket’s peer.

The connect method will connect the socket to a peer.

Examples
use async_std::os::unix::net::UnixDatagram;

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

Receives data from the socket.

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

Examples
use async_std::os::unix::net::UnixDatagram;

let socket = UnixDatagram::unbound()?;
let mut buf = vec![0; 1024];
let (n, peer) = socket.recv_from(&mut buf).await?;

Receives data from the socket.

On success, returns the number of bytes read.

Examples
use async_std::os::unix::net::UnixDatagram;

let socket = UnixDatagram::bind("/tmp/socket").await?;
let mut buf = vec![0; 1024];
let n = socket.recv(&mut buf).await?;

Sends data on the socket to the specified address.

On success, returns the number of bytes written.

Examples
use async_std::os::unix::net::UnixDatagram;

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

Sends data on the socket to the socket’s peer.

On success, returns the number of bytes written.

Examples
use async_std::os::unix::net::UnixDatagram;

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

Shut down the read, write, or both halves of this connection.

This function will cause all pending and future I/O calls on the specified portions to immediately return with an appropriate value (see the documentation of Shutdown).

Examples
use async_std::os::unix::net::UnixDatagram;
use std::net::Shutdown;

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

Trait Implementations

Extracts the raw file descriptor. Read more

Formats the value using the given formatter. Read more

Converts a std::os::unix::net::UnixDatagram into its asynchronous equivalent.

Constructs a new instance of Self from the given raw file descriptor. Read more

Consumes this object, returning the raw underlying file descriptor. Read more

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