pub struct UnixDatagram { /* private fields */ }
Expand description
An I/O object representing a Unix datagram socket.
Implementations§
Source§impl UnixDatagram
impl UnixDatagram
Sourcepub fn bind(path: impl AsRef<Path>) -> Result<UnixDatagram>
pub fn bind(path: impl AsRef<Path>) -> Result<UnixDatagram>
Creates a new UnixDatagram
bound to the specified path.
§Examples
use futures_net::uds::UnixDatagram;
let sock = UnixDatagram::bind("/tmp/sock")?;
Sourcepub fn pair() -> Result<(UnixDatagram, UnixDatagram)>
pub fn pair() -> Result<(UnixDatagram, UnixDatagram)>
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 event loop whose handle is also provided.
§Examples
use futures_net::uds::UnixDatagram;
let (sock1, sock2) = UnixDatagram::pair()?;
Sourcepub fn unbound() -> Result<UnixDatagram>
pub fn unbound() -> Result<UnixDatagram>
Creates a new UnixDatagram
which is not bound to any address.
§Examples
use futures_net::uds::UnixDatagram;
let sock = UnixDatagram::unbound()?;
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address that this socket is bound to.
§Examples
use futures_net::uds::UnixDatagram;
let stream = UnixDatagram::bind("/tmp/sock")?;
let addr = stream.local_addr()?;
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the address of this socket’s peer.
The connect
method will connect the socket to a peer.
§Examples
use futures_net::uds::UnixDatagram;
let stream = UnixDatagram::bind("/tmp/sock")?;
let addr = stream.peer_addr()?;
Sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
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 futures_net::uds::UnixDatagram;
use std::net::Shutdown;
let stream = UnixDatagram::bind("/tmp/sock")?;
stream.shutdown(Shutdown::Both)?;
Sourcepub fn send_to<'a, 'b>(
&'a mut self,
buf: &'b [u8],
target: &'b PathBuf,
) -> SendTo<'a, 'b>
pub fn send_to<'a, 'b>( &'a mut self, buf: &'b [u8], target: &'b PathBuf, ) -> SendTo<'a, 'b>
Sends data on the socket to the given address. On success, returns the number of bytes written.
§Examples
use futures_net::udp::UdpSocket;
const THE_MERCHANT_OF_VENICE: &[u8] = b"
If you prick us, do we not bleed?
If you tickle us, do we not laugh?
If you poison us, do we not die?
And if you wrong us, shall we not revenge?
";
let addr = "/tmp/out.socket".parse()?;
let target = "/tmp/in.socket".parse()?;
let mut socket = UdpSocket::bind(&addr)?;
socket.send_to(THE_MERCHANT_OF_VENICE, &target).await?;
Sourcepub fn recv_from<'a, 'b>(&'a mut self, buf: &'b mut [u8]) -> RecvFrom<'a, 'b>
pub fn recv_from<'a, 'b>(&'a mut self, buf: &'b mut [u8]) -> RecvFrom<'a, 'b>
Receives data from the socket. On success, returns the number of bytes read and the address from whence the data came.
§Exampes
use futures_net::udp::UdpSocket;
let addr = "/tmp/in.socket".parse()?;
let mut socket = UdpSocket::bind(&addr)?;
let mut buf = vec![0; 1024];
socket.recv_from(&mut buf).await?;
Trait Implementations§
Source§impl AsRawFd for UnixDatagram
impl AsRawFd for UnixDatagram
Source§impl AsyncDatagram for UnixDatagram
impl AsyncDatagram for UnixDatagram
Source§impl AsyncReadReady for UnixDatagram
impl AsyncReadReady for UnixDatagram
Source§impl AsyncWriteReady for UnixDatagram
impl AsyncWriteReady for UnixDatagram
Source§impl Debug for UnixDatagram
impl Debug for UnixDatagram
Source§impl TakeError for UnixDatagram
impl TakeError for UnixDatagram
Source§fn take_error(&self) -> Result<Option<Self::Ok>, Self::Err>
fn take_error(&self) -> Result<Option<Self::Ok>, Self::Err>
Returns the value of the SO_ERROR
option.
§Examples
use async_ready::TakeError;
use futures_net::uds::UnixDatagram;
let stream = UnixDatagram::bind("/tmp/sock")?;
if let Ok(Some(err)) = stream.take_error() {
println!("Got error: {:?}", err);
}