[][src]Struct async_std::os::unix::net::UnixDatagram

pub struct UnixDatagram { /* fields omitted */ }
This is supported on Unix only.

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?;

Methods

impl UnixDatagram[src]

pub async fn bind<P: AsRef<Path>>(path: P) -> Result<UnixDatagram>[src]

This is supported on Unix only.

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?;

pub fn unbound() -> Result<UnixDatagram>[src]

This is supported on Unix only.

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

Examples

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

let socket = UnixDatagram::unbound()?;

pub fn pair() -> Result<(UnixDatagram, UnixDatagram)>[src]

This is supported on Unix only.

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()?;

pub async fn connect<'_, P: AsRef<Path>>(&'_ self, path: P) -> Result<()>[src]

This is supported on Unix only.

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?;

pub fn local_addr(&self) -> Result<SocketAddr>[src]

This is supported on Unix only.

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()?;

pub fn peer_addr(&self) -> Result<SocketAddr>[src]

This is supported on Unix only.

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()?;

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

This is supported on Unix only.

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?;

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

This is supported on Unix only.

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?;

pub async fn send_to<'_, '_, P: AsRef<Path>>(
    &'_ self,
    buf: &'_ [u8],
    path: P
) -> Result<usize>
[src]

This is supported on Unix only.

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?;

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

This is supported on Unix only.

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?;

pub fn shutdown(&self, how: Shutdown) -> Result<()>[src]

This is supported on Unix only.

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

impl AsRawFd for UnixDatagram[src]

impl FromRawFd for UnixDatagram[src]

impl IntoRawFd for UnixDatagram[src]

impl From<UnixDatagram> for UnixDatagram[src]

fn from(datagram: UnixDatagram) -> UnixDatagram[src]

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

impl Debug for UnixDatagram[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]