From 0c73f13c8beebb42911566f3f98ac78d8a941453 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 22 Mar 2021 22:50:48 -0700 Subject: [PATCH] ActixStream readiness methods return Ready object (#293) --- actix-rt/CHANGES.md | 3 +++ actix-rt/Cargo.toml | 2 +- actix-rt/src/lib.rs | 37 +++++++++++++++++++++---------- actix-tls/src/accept/nativetls.rs | 6 ++--- actix-tls/src/accept/openssl.rs | 6 ++--- actix-tls/src/accept/rustls.rs | 6 ++--- 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 1fd7b25b..83ecc5ed 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 92f10b85..126056ec 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 e21cd651..bd2e165d 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 std::{ + future::Future, + io, + task::{Context, Poll}, + }; - use tokio::io::{AsyncRead, AsyncWrite}; + 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 98a103a8..614bdad3 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 f94e3c2d..4afcdcab 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 753d68ac..ffac687a 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) } }