Struct async_std::os::unix::net::UnixDatagram [−][src]
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?;
Implementations
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]
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 Debug for UnixDatagram
[src]
impl From<UnixDatagram> for UnixDatagram
[src]
fn from(datagram: StdUnixDatagram) -> UnixDatagram
[src]
Converts a std::os::unix::net::UnixDatagram
into its asynchronous equivalent.
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]
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,
pub 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, 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.
pub 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>,