Struct actix_rt::net::UnixDatagram[][src]

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

An I/O object representing a Unix datagram socket.

Implementations

Creates a new UnixDatagram bound to the specified path.

Creates an unnamed pair of connected sockets.

This function will create a pair of interconnected Unix sockets for communicating back and forth between one another. Each socket will be associated with the default event loop’s handle.

Consumes a UnixDatagram in the standard library and returns a nonblocking UnixDatagram from this crate.

The returned datagram will be associated with the given event loop specified by handle and is ready to perform I/O.

Panics

This function panics if thread-local runtime is not set.

The runtime is usually set implicitly when this function is called from a future driven by a tokio runtime, otherwise runtime can be set explicitly with Handle::enter function.

Creates a new UnixDatagram which is not bound to any address.

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.

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

Try to send a datagram to the peer without waiting.

use tokio::net::UnixDatagram;

let bytes = b"bytes";
// We use a socket pair so that they are assigned
// each other as a peer.
let (mut first, mut second) = UnixDatagram::pair()?;

let size = first.try_send(bytes)?;
assert_eq!(size, bytes.len());

let mut buffer = vec![0u8; 24];
let size = second.try_recv(&mut buffer)?;

let dgram = &buffer.as_slice()[..size];
assert_eq!(dgram, bytes);

Try to send a datagram to the peer without waiting.

use {
    tokio::net::UnixDatagram,
    tempfile::tempdir,
};

let bytes = b"bytes";
// We use a temporary directory so that the socket
// files left by the bound sockets will get cleaned up.
let tmp = tempdir().unwrap();

let server_path = tmp.path().join("server");
let mut server = UnixDatagram::bind(&server_path)?;

let client_path = tmp.path().join("client");
let mut client = UnixDatagram::bind(&client_path)?;

let size = client.try_send_to(bytes, &server_path)?;
assert_eq!(size, bytes.len());

let mut buffer = vec![0u8; 24];
let (size, addr) = server.try_recv_from(&mut buffer)?;

let dgram = &buffer.as_slice()[..size];
assert_eq!(dgram, bytes);
assert_eq!(addr.as_pathname().unwrap(), &client_path);

Receives data from the socket.

Try to receive a datagram from the peer without waiting.

Sends data on the socket to the specified address.

Receives data from the socket.

Try to receive data from the socket without waiting.

Returns the local address that this socket is bound to.

Returns the address of this socket’s peer.

The connect method will connect the socket to a peer.

Returns the value of the SO_ERROR option.

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

Split a UnixDatagram into a receive half and a send half, which can be used to receive and send the datagram concurrently.

This method is more efficient than into_split, but the halves cannot be moved into independently spawned tasks.

Split a UnixDatagram into a receive half and a send half, which can be used to receive and send the datagram concurrently.

Unlike split, the owned halves can be moved to separate tasks, however this comes at the cost of a heap allocation.

Note: Dropping the write half will shut down the write half of the datagram. This is equivalent to calling shutdown(Write).

Trait Implementations

Extracts the raw file descriptor. Read more

Formats the value using the given formatter. Read more

Consumes stream, returning the tokio I/O object.

This is equivalent to UnixDatagram::from_std(stream).

The type returned in the event of a conversion error.

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

Performs the conversion.

Performs the conversion.

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.