[−][src]Struct smol::net::unix::UnixDatagram
A Unix datagram socket.
After creating a UnixDatagram
by bind
ing 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
impl UnixDatagram
[src]
pub fn bind<P>(path: P) -> Result<UnixDatagram, Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Creates a new UnixDatagram
bound to the given address.
Examples
use async_net::unix::UnixDatagram; let socket = UnixDatagram::bind("/tmp/socket")?;
pub fn unbound() -> Result<UnixDatagram, Error>
[src]
Creates a Unix datagram socket not bound to any address.
Examples
use async_net::unix::UnixDatagram; let socket = UnixDatagram::unbound()?;
pub fn pair() -> Result<(UnixDatagram, UnixDatagram), Error>
[src]
Creates a pair of connected Unix datagram sockets.
Examples
use async_net::unix::UnixDatagram; let (socket1, socket2) = UnixDatagram::pair()?;
pub fn connect<P>(&self, path: P) -> Result<(), Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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")?;
pub fn local_addr(&self) -> Result<SocketAddr, Error>
[src]
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()?);
pub fn peer_addr(&self) -> Result<SocketAddr, Error>
[src]
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()?);
pub async fn recv_from(
&'_ self,
buf: &'_ mut [u8]
) -> Result<(usize, SocketAddr), Error>
[src]
&'_ self,
buf: &'_ mut [u8]
) -> Result<(usize, SocketAddr), Error>
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);
pub async fn send_to<P>(
&'_ self,
buf: &'_ [u8],
path: P
) -> Result<usize, Error> where
P: AsRef<Path>,
[src]
&'_ self,
buf: &'_ [u8],
path: P
) -> Result<usize, Error> where
P: AsRef<Path>,
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?;
pub async fn recv(&'_ self, buf: &'_ mut [u8]) -> Result<usize, Error>
[src]
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?;
pub async fn send(&'_ self, buf: &'_ [u8]) -> Result<usize, Error>
[src]
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?;
pub fn shutdown(&self, how: Shutdown) -> Result<(), Error>
[src]
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
impl AsRawFd for UnixDatagram
[src]
impl Clone for UnixDatagram
[src]
fn clone(&self) -> UnixDatagram
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for UnixDatagram
[src]
impl From<Async<UnixDatagram>> for UnixDatagram
[src]
fn from(socket: Async<UnixDatagram>) -> UnixDatagram
[src]
impl TryFrom<UnixDatagram> for UnixDatagram
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(socket: UnixDatagram) -> Result<UnixDatagram, Error>
[src]
Auto Trait Implementations
impl RefUnwindSafe for UnixDatagram
impl Send for UnixDatagram
impl Sync for UnixDatagram
impl Unpin for UnixDatagram
impl UnwindSafe for UnixDatagram
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut Tⓘ
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,