From bf63606a32873ca3a6f65f8fde9ea0481803fe50 Mon Sep 17 00:00:00 2001 From: jean-airoldie <25088801+jean-airoldie@users.noreply.github.com> Date: Sun, 22 Dec 2019 23:22:45 -0500 Subject: [PATCH] Added try_send{,_to} & try_recv{,from} for split UnixDatagram --- tokio/src/net/unix/split.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tokio/src/net/unix/split.rs b/tokio/src/net/unix/split.rs index 2b9cc4dcabf..03c8c9b0df4 100644 --- a/tokio/src/net/unix/split.rs +++ b/tokio/src/net/unix/split.rs @@ -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 { + 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<'_> { @@ -117,6 +127,11 @@ 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 { + self.0.try_send(buf) + } + /// Sends a datagram to the specified address. pub async fn send_to

(&mut self, buf: &[u8], target: P) -> io::Result where @@ -124,5 +139,9 @@ impl SendHalf<'_> { { 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

(&mut self, buf: &[u8], target: P) -> io::Result { + self.0.try_send_to(buf, target) + } +}