diff --git a/tokio/src/net/unix/datagram.rs b/tokio/src/net/unix/datagram.rs index ebaddefb998..6c7939c9fea 100644 --- a/tokio/src/net/unix/datagram.rs +++ b/tokio/src/net/unix/datagram.rs @@ -103,6 +103,13 @@ impl UnixDatagram { self.io.get_ref().send(buf) } + // Poll IO functions that takes `&self` are provided for the split API. + // + // See `poll_send_priv` for more info. + pub(crate) fn try_send_priv(&self, buf: &[u8]) -> io::Result { + self.io.get_ref().send(buf) + } + /// Try to send a datagram to the peer without waiting. /// /// ``` @@ -143,6 +150,16 @@ impl UnixDatagram { self.io.get_ref().send_to(buf, target) } + // Poll IO functions that takes `&self` are provided for the split API. + // + // See `poll_send_priv` for more info. + pub(crate) fn try_send_to_priv

(&self, buf: &[u8], target: P) -> io::Result + where + P: AsRef + { + self.io.get_ref().send_to(buf, target) + } + // Poll IO functions that takes `&self` are provided for the split API. // // They are not public because (taken from the doc of `PollEvented`): @@ -179,6 +196,13 @@ impl UnixDatagram { self.io.get_ref().recv(buf) } + // Poll IO functions that takes `&self` are provided for the split API. + // + // See `poll_send_priv` for more info. + pub(crate) fn try_recv_priv(&self, buf: &mut [u8]) -> io::Result { + self.io.get_ref().recv(buf) + } + pub(crate) fn poll_recv_priv( &self, cx: &mut Context<'_>, @@ -230,6 +254,13 @@ impl UnixDatagram { self.io.get_ref().recv_from(buf) } + // Poll IO functions that takes `&self` are provided for the split API. + // + // See `poll_send_priv` for more info. + pub(crate) fn try_recv_from_priv(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { + self.io.get_ref().recv_from(buf) + } + pub(crate) fn poll_recv_from_priv( &self, cx: &mut Context<'_>, diff --git a/tokio/src/net/unix/split.rs b/tokio/src/net/unix/split.rs index 2b9cc4dcabf..edd64f64343 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_priv(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_priv(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_priv(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,12 @@ 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 + where + P: AsRef, + { + self.0.try_send_to_priv(buf, target) + } +}