[−][src]Struct async_std::os::unix::net::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.
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]
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]
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]
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]
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]
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]
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]
&'_ self,
buf: &'_ mut [u8]
) -> Result<(usize, SocketAddr)>
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]
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]
&'_ self,
buf: &'_ [u8],
path: P
) -> Result<usize>
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]
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]
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]
unsafe fn from_raw_fd(fd: RawFd) -> UnixDatagram
[src]
impl IntoRawFd for UnixDatagram
[src]
fn into_raw_fd(self) -> RawFd
[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
impl Send for UnixDatagram
impl Sync for UnixDatagram
impl Unpin for UnixDatagram
impl UnwindSafe for UnixDatagram
impl RefUnwindSafe for UnixDatagram
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,