From 4e39c9b818eb8af064bb9f45f47e3cfc6593de95 Mon Sep 17 00:00:00 2001 From: masnagam Date: Tue, 17 Nov 2020 02:51:06 +0900 Subject: net: restore TcpStream::{poll_read_ready, poll_write_ready} (#2743) --- tokio/src/net/tcp/stream.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tokio/src/net/tcp/stream.rs') diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 2ac37a2b..8a157e1c 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -356,6 +356,17 @@ impl TcpStream { Ok(()) } + /// Polls for read readiness. + /// + /// This function is intended for cases where creating and pinning a future + /// via [`readable`] is not feasible. Where possible, using [`readable`] is + /// preferred, as this supports polling from multiple tasks at once. + /// + /// [`readable`]: method@Self::readable + pub fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { + self.io.registration().poll_read_ready(cx).map_ok(|_| ()) + } + /// Try to read data from the stream into the provided buffer, returning how /// many bytes were read. /// @@ -467,6 +478,17 @@ impl TcpStream { Ok(()) } + /// Polls for write readiness. + /// + /// This function is intended for cases where creating and pinning a future + /// via [`writable`] is not feasible. Where possible, using [`writable`] is + /// preferred, as this supports polling from multiple tasks at once. + /// + /// [`writable`]: method@Self::writable + pub fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { + self.io.registration().poll_write_ready(cx).map_ok(|_| ()) + } + /// Try to write a buffer to the stream, returning how many bytes were /// written. /// -- cgit v1.2.3