diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 1fd7b25ba8..83ecc5ed7b 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* `ActixStream::{poll_read_ready, poll_write_ready}` would return `Ready` in Ok variant. [#293] + +[#293] https://github.com/actix/actix-net/pull/293 ## 2.1.0 - 2021-02-24 diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index 92f10b85a0..126056eca6 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -26,7 +26,7 @@ macros = ["actix-macros"] actix-macros = { version = "0.2.0", optional = true } futures-core = { version = "0.3", default-features = false } -tokio = { version = "1.2", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } +tokio = { version = "1.3", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } [dev-dependencies] tokio = { version = "1.2", features = ["full"] } diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index e21cd6510d..bd2e165d18 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -72,9 +72,14 @@ pub mod signal { pub mod net { //! TCP/UDP/Unix bindings (mostly Tokio re-exports). - use std::task::{Context, Poll}; - - use tokio::io::{AsyncRead, AsyncWrite}; + use std::{ + future::Future, + io, + task::{Context, Poll}, + }; + + pub use tokio::io::Ready; + use tokio::io::{AsyncRead, AsyncWrite, Interest}; pub use tokio::net::UdpSocket; pub use tokio::net::{TcpListener, TcpSocket, TcpStream}; @@ -86,32 +91,40 @@ pub mod net { /// Poll stream and check read readiness of Self. /// /// See [tokio::net::TcpStream::poll_read_ready] for detail on intended use. - fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll>; + fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll>; /// Poll stream and check write readiness of Self. /// /// See [tokio::net::TcpStream::poll_write_ready] for detail on intended use. - fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll>; + fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll>; } impl ActixStream for TcpStream { - fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { - TcpStream::poll_read_ready(self, cx) + fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { + let ready = self.ready(Interest::READABLE); + tokio::pin!(ready); + ready.poll(cx) } - fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { - TcpStream::poll_write_ready(self, cx) + fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { + let ready = self.ready(Interest::WRITABLE); + tokio::pin!(ready); + ready.poll(cx) } } #[cfg(unix)] impl ActixStream for UnixStream { - fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { - UnixStream::poll_read_ready(self, cx) + fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { + let ready = self.ready(Interest::READABLE); + tokio::pin!(ready); + ready.poll(cx) } - fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { - UnixStream::poll_write_ready(self, cx) + fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { + let ready = self.ready(Interest::WRITABLE); + tokio::pin!(ready); + ready.poll(cx) } } } diff --git a/actix-tls/src/accept/nativetls.rs b/actix-tls/src/accept/nativetls.rs index 98a103a811..614bdad36e 100644 --- a/actix-tls/src/accept/nativetls.rs +++ b/actix-tls/src/accept/nativetls.rs @@ -6,7 +6,7 @@ use std::{ }; use actix_codec::{AsyncRead, AsyncWrite, ReadBuf}; -use actix_rt::net::ActixStream; +use actix_rt::net::{ActixStream, Ready}; use actix_service::{Service, ServiceFactory}; use actix_utils::counter::Counter; use futures_core::future::LocalBoxFuture; @@ -80,11 +80,11 @@ impl AsyncWrite for TlsStream { } impl ActixStream for TlsStream { - fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { + fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { T::poll_read_ready((&**self).get_ref().get_ref().get_ref(), cx) } - fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { + fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { T::poll_write_ready((&**self).get_ref().get_ref().get_ref(), cx) } } diff --git a/actix-tls/src/accept/openssl.rs b/actix-tls/src/accept/openssl.rs index f94e3c2da7..4afcdcab5e 100644 --- a/actix-tls/src/accept/openssl.rs +++ b/actix-tls/src/accept/openssl.rs @@ -7,7 +7,7 @@ use std::{ }; use actix_codec::{AsyncRead, AsyncWrite, ReadBuf}; -use actix_rt::net::ActixStream; +use actix_rt::net::{ActixStream, Ready}; use actix_service::{Service, ServiceFactory}; use actix_utils::counter::{Counter, CounterGuard}; use futures_core::{future::LocalBoxFuture, ready}; @@ -82,11 +82,11 @@ impl AsyncWrite for TlsStream { } impl ActixStream for TlsStream { - fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { + fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { T::poll_read_ready((&**self).get_ref(), cx) } - fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { + fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { T::poll_write_ready((&**self).get_ref(), cx) } } diff --git a/actix-tls/src/accept/rustls.rs b/actix-tls/src/accept/rustls.rs index 753d68acac..ffac687aa7 100644 --- a/actix-tls/src/accept/rustls.rs +++ b/actix-tls/src/accept/rustls.rs @@ -8,7 +8,7 @@ use std::{ }; use actix_codec::{AsyncRead, AsyncWrite, ReadBuf}; -use actix_rt::net::ActixStream; +use actix_rt::net::{ActixStream, Ready}; use actix_service::{Service, ServiceFactory}; use actix_utils::counter::{Counter, CounterGuard}; use futures_core::future::LocalBoxFuture; @@ -82,11 +82,11 @@ impl AsyncWrite for TlsStream { } impl ActixStream for TlsStream { - fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { + fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { T::poll_read_ready((&**self).get_ref().0, cx) } - fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { + fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { T::poll_write_ready((&**self).get_ref().0, cx) } }