Skip to content

Commit

Permalink
Added try_send{,_to} & try_recv{,from} for split UnixDatagram
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-airoldie committed Dec 23, 2019
1 parent 1d8fa9e commit bf63606
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tokio/src/net/unix/split.rs
Expand Up @@ -105,10 +105,20 @@ impl RecvHalf<'_> {
poll_fn(|cx| self.0.poll_recv_priv(cx, buf)).await
}

/// Try to receive a datagram from the peer without waiting.
pub fn try_recv(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.try_recv(buf)
}

/// Receives a datagram with the source address from the socket.
pub async fn recv_from(&mut self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
poll_fn(|cx| self.0.poll_recv_from_priv(cx, buf)).await
}

/// Try to receive data from the socket without waiting.
pub fn try_recv_from(&mut self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
self.0.try_recv_from(buf)
}
}

impl SendHalf<'_> {
Expand All @@ -117,12 +127,21 @@ impl SendHalf<'_> {
poll_fn(|cx| self.0.poll_send_priv(cx, buf)).await
}

/// Try to send a datagram to the peer without waiting.
pub fn try_send(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.try_send(buf)
}

/// Sends a datagram to the specified address.
pub async fn send_to<P>(&mut self, buf: &[u8], target: P) -> io::Result<usize>
where
P: AsRef<Path> + Unpin,
{
poll_fn(|cx| self.0.poll_send_to_priv(cx, buf, target.as_ref())).await
}
}

/// Try to send a datagram to the peer without waiting.
pub fn try_send_to<P>(&mut self, buf: &[u8], target: P) -> io::Result<usize> {
self.0.try_send_to(buf, target)
}
}

0 comments on commit bf63606

Please sign in to comment.