From 3e1ebed56fa58ed3c9f5e380645aa7f08e1e689c Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Tue, 16 Mar 2021 13:17:32 +0800 Subject: [PATCH 1/5] return ready state in ActixStream::poll_xxx_ready --- Cargo.toml | 2 ++ actix-rt/Cargo.toml | 2 +- actix-rt/src/lib.rs | 26 +++++++++++++++----------- actix-tls/src/accept/nativetls.rs | 6 +++--- actix-tls/src/accept/openssl.rs | 6 +++--- actix-tls/src/accept/rustls.rs | 6 +++--- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 78e54d359a..30ca638807 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,5 @@ actix-tls = { path = "actix-tls" } actix-tracing = { path = "actix-tracing" } actix-utils = { path = "actix-utils" } bytestring = { path = "bytestring" } + +tokio = { git = "https://github.com/fakeshadow/tokio", branch = "feature/net_poll_ready" } \ No newline at end of file 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..4afa8ea099 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -72,8 +72,12 @@ pub mod signal { pub mod net { //! TCP/UDP/Unix bindings (mostly Tokio re-exports). - use std::task::{Context, Poll}; + use std::{ + io, + task::{Context, Poll}, + }; + pub use tokio::io::Ready; use tokio::io::{AsyncRead, AsyncWrite}; pub use tokio::net::UdpSocket; pub use tokio::net::{TcpListener, TcpSocket, TcpStream}; @@ -86,32 +90,32 @@ 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> { + TcpStream::poll_ready(self, 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> { + TcpStream::poll_ready(self, 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> { + UnixStream::poll_ready(self, 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> { + UnixStream::poll_ready(self, 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) } } From f8f534ac34aa3f6c3c10114222c7fc356e13f262 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 22 Mar 2021 00:23:49 +0800 Subject: [PATCH 2/5] remove override --- actix-rt/src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index 4afa8ea099..950c30cb82 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -73,12 +73,13 @@ pub mod net { //! TCP/UDP/Unix bindings (mostly Tokio re-exports). use std::{ + future::Future, io, task::{Context, Poll}, }; pub use tokio::io::Ready; - use tokio::io::{AsyncRead, AsyncWrite}; + use tokio::io::{AsyncRead, AsyncWrite, Interest}; pub use tokio::net::UdpSocket; pub use tokio::net::{TcpListener, TcpSocket, TcpStream}; @@ -100,22 +101,30 @@ pub mod net { impl ActixStream for TcpStream { fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { - TcpStream::poll_ready(self, cx) + let ready = self.ready(Interest::READABLE); + tokio::pin!(ready); + ready.poll(cx) } fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { - TcpStream::poll_ready(self, cx) + 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_ready(self, cx) + let ready = self.ready(Interest::READABLE); + self::pin!(ready); + ready.poll(cx) } fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { - UnixStream::poll_ready(self, cx) + let ready = self.ready(Interest::WRITABLE); + self::pin!(ready); + ready.poll(cx) } } } From 5fd7f8f18738635b9bb24b9fe37a7151b11663a3 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 22 Mar 2021 00:26:24 +0800 Subject: [PATCH 3/5] pin async fn ready in poll_xxx_ready --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 30ca638807..78e54d359a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,5 +23,3 @@ actix-tls = { path = "actix-tls" } actix-tracing = { path = "actix-tracing" } actix-utils = { path = "actix-utils" } bytestring = { path = "bytestring" } - -tokio = { git = "https://github.com/fakeshadow/tokio", branch = "feature/net_poll_ready" } \ No newline at end of file From 79d02893f9ff60b9b6840700754e2ecca66aae80 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 22 Mar 2021 00:29:58 +0800 Subject: [PATCH 4/5] update changelog --- actix-rt/CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) 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 From 62f962ae5b0dfe944232348575477c90b4daf58b Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 22 Mar 2021 00:41:07 +0800 Subject: [PATCH 5/5] fix unix feature build --- actix-rt/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index 950c30cb82..bd2e165d18 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -117,13 +117,13 @@ pub mod net { impl ActixStream for UnixStream { fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll> { let ready = self.ready(Interest::READABLE); - self::pin!(ready); + tokio::pin!(ready); ready.poll(cx) } fn poll_write_ready(&self, cx: &mut Context<'_>) -> Poll> { let ready = self.ready(Interest::WRITABLE); - self::pin!(ready); + tokio::pin!(ready); ready.poll(cx) } }