From 02a902068f9df39c3fedb2097e11569a69600ca2 Mon Sep 17 00:00:00 2001 From: Juan Aguilar Date: Sun, 13 Dec 2020 20:26:57 +0100 Subject: [PATCH 1/2] Refactor LocalWaker (#224) --- actix-rt/src/arbiter.rs | 2 +- actix-server/src/builder.rs | 2 +- actix-server/src/signals.rs | 7 ++----- actix-utils/src/dispatcher.rs | 6 ++---- actix-utils/src/inflight.rs | 2 +- actix-utils/src/order.rs | 7 ++++++- actix-utils/src/task.rs | 11 ++++++++--- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs index 9a5f1f93..295d2624 100644 --- a/actix-rt/src/arbiter.rs +++ b/actix-rt/src/arbiter.rs @@ -333,7 +333,7 @@ impl Future for CleanupPending { let mut pending = cell.borrow_mut(); let mut i = 0; while i != pending.len() { - if let Poll::Ready(_) = Pin::new(&mut pending[i]).poll(cx) { + if Pin::new(&mut pending[i]).poll(cx).is_ready() { pending.remove(i); } else { i += 1; diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index 8a90d598..64a45df9 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -286,7 +286,7 @@ impl ServerBuilder { // handle signals if !self.no_signals { - Signals::start(self.server.clone()).unwrap(); + Signals::start(self.server.clone()); } // start http server actor diff --git a/actix-server/src/signals.rs b/actix-server/src/signals.rs index b6339621..4fc51fc1 100644 --- a/actix-server/src/signals.rs +++ b/actix-server/src/signals.rs @@ -1,5 +1,4 @@ use std::future::Future; -use std::io; use std::pin::Pin; use std::task::{Context, Poll}; @@ -24,13 +23,13 @@ pub(crate) enum Signal { pub(crate) struct Signals { srv: Server, #[cfg(not(unix))] - stream: Pin>>>, + stream: Pin>>>, #[cfg(unix)] streams: Vec<(Signal, actix_rt::signal::unix::Signal)>, } impl Signals { - pub(crate) fn start(srv: Server) -> io::Result<()> { + pub(crate) fn start(srv: Server) { actix_rt::spawn(lazy(|_| { #[cfg(not(unix))] { @@ -66,8 +65,6 @@ impl Signals { actix_rt::spawn(Signals { srv, streams }) } })); - - Ok(()) } } diff --git a/actix-utils/src/dispatcher.rs b/actix-utils/src/dispatcher.rs index 15d3ccf7..1ee72564 100644 --- a/actix-utils/src/dispatcher.rs +++ b/actix-utils/src/dispatcher.rs @@ -290,10 +290,8 @@ where } State::Error(_) => { // flush write buffer - if !this.framed.is_write_buf_empty() { - if let Poll::Pending = this.framed.flush(cx) { - return Poll::Pending; - } + if !this.framed.is_write_buf_empty() && this.framed.flush(cx).is_pending() { + return Poll::Pending; } Poll::Ready(Err(this.state.take_error())) } diff --git a/actix-utils/src/inflight.rs b/actix-utils/src/inflight.rs index 5ed987c7..8975a2d2 100644 --- a/actix-utils/src/inflight.rs +++ b/actix-utils/src/inflight.rs @@ -74,7 +74,7 @@ where type Future = InFlightServiceResponse; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - if let Poll::Pending = self.service.poll_ready(cx)? { + if self.service.poll_ready(cx)?.is_pending() { Poll::Pending } else if !self.count.available(cx) { log::trace!("InFlight limit exceeded"); diff --git a/actix-utils/src/order.rs b/actix-utils/src/order.rs index c418f1d3..2d11b491 100644 --- a/actix-utils/src/order.rs +++ b/actix-utils/src/order.rs @@ -160,7 +160,12 @@ where } // check nested service - if let Poll::Pending = self.service.poll_ready(cx).map_err(InOrderError::Service)? { + if self + .service + .poll_ready(cx) + .map_err(InOrderError::Service)? + .is_pending() + { Poll::Pending } else { Poll::Ready(Ok(())) diff --git a/actix-utils/src/task.rs b/actix-utils/src/task.rs index dca386b8..cb32eb8d 100644 --- a/actix-utils/src/task.rs +++ b/actix-utils/src/task.rs @@ -19,6 +19,7 @@ use std::{fmt, rc}; /// /// A single `AtomicWaker` may be reused for any number of calls to `register` or /// `wake`. +// TODO: Refactor to Cell when remove deprecated methods (@botika) #[derive(Default)] pub struct LocalWaker { pub(crate) waker: UnsafeCell>, @@ -34,6 +35,10 @@ impl LocalWaker { } } + #[deprecated( + since = "2.1.0", + note = "In favor of `wake`. State of the register doesn't matter at `wake` up" + )] #[inline] /// Check if waker has been registered. pub fn is_registered(&self) -> bool { @@ -47,9 +52,8 @@ impl LocalWaker { pub fn register(&self, waker: &Waker) -> bool { unsafe { let w = self.waker.get(); - let is_registered = (*w).is_some(); - *w = Some(waker.clone()); - is_registered + let last_waker = w.replace(Some(waker.clone())); + last_waker.is_some() } } @@ -63,6 +67,7 @@ impl LocalWaker { } } + #[inline] /// Returns the last `Waker` passed to `register`, so that the user can wake it. /// /// If a waker has not been registered, this returns `None`. From b296d0f254c46c5485f7d2ae760875eefa41c3a5 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Mon, 14 Dec 2020 13:52:30 +0530 Subject: [PATCH 2/2] Intradoc links conversion (#227) * intra doc conversion * rm trailing blank comment --- actix-codec/src/lib.rs | 2 -- actix-connect/src/connect.rs | 4 ++-- actix-rt/src/runtime.rs | 4 ++-- actix-rt/src/system.rs | 2 -- actix-service/src/lib.rs | 4 ++-- actix-tracing/src/lib.rs | 2 -- string/src/lib.rs | 2 +- 7 files changed, 7 insertions(+), 13 deletions(-) diff --git a/actix-codec/src/lib.rs b/actix-codec/src/lib.rs index 07939549..8c346052 100644 --- a/actix-codec/src/lib.rs +++ b/actix-codec/src/lib.rs @@ -4,8 +4,6 @@ //! [`AsyncWrite`], to framed streams implementing [`Sink`] and [`Stream`]. //! Framed streams are also known as `transports`. //! -//! [`AsyncRead`]: AsyncRead -//! [`AsyncWrite`]: AsyncWrite //! [`Sink`]: futures_sink::Sink //! [`Stream`]: futures_core::Stream diff --git a/actix-connect/src/connect.rs b/actix-connect/src/connect.rs index 7d5531e5..37fa9c6e 100644 --- a/actix-connect/src/connect.rs +++ b/actix-connect/src/connect.rs @@ -138,7 +138,7 @@ impl fmt::Display for Connect { } } -/// Iterator over addresses in a [`Connect`](struct.Connect.html) request. +/// Iterator over addresses in a [`Connect`] request. #[derive(Clone)] pub struct ConnectAddrsIter<'a> { inner: Either, vec_deque::Iter<'a, SocketAddr>>, @@ -173,7 +173,7 @@ impl ExactSizeIterator for ConnectAddrsIter<'_> {} impl FusedIterator for ConnectAddrsIter<'_> {} -/// Owned iterator over addresses in a [`Connect`](struct.Connect.html) request. +/// Owned iterator over addresses in a [`Connect`] request. #[derive(Debug)] pub struct ConnectTakeAddrsIter { inner: Either, vec_deque::IntoIter>, diff --git a/actix-rt/src/runtime.rs b/actix-rt/src/runtime.rs index bbafb6f0..d3231192 100644 --- a/actix-rt/src/runtime.rs +++ b/actix-rt/src/runtime.rs @@ -7,7 +7,7 @@ use tokio::{runtime, task::LocalSet}; /// /// See [module level][mod] documentation for more details. /// -/// [mod]: index.html +/// [mod]: crate #[derive(Debug)] pub struct Runtime { local: LocalSet, @@ -34,7 +34,7 @@ impl Runtime { /// /// See [module level][mod] documentation for more details. /// - /// [mod]: index.html + /// [mod]: crate /// /// # Examples /// diff --git a/actix-rt/src/system.rs b/actix-rt/src/system.rs index f33854ba..2e1ae174 100644 --- a/actix-rt/src/system.rs +++ b/actix-rt/src/system.rs @@ -66,7 +66,6 @@ impl System { /// It means that using this method currently it is impossible to make `actix-rt` work in the /// alternative `tokio` `Runtime`s (e.g. provided by [`tokio_compat`]). /// - /// [`Arbiter`]: struct.Arbiter.html /// [`tokio_compat`]: https://crates.io/crates/tokio-compat /// /// # Examples @@ -131,7 +130,6 @@ impl System { /// It means that using this method currently it is impossible to make `actix-rt` work in the /// alternative `tokio` `Runtime`s (e.g. provided by `tokio_compat`). /// - /// [`Arbiter`]: struct.Arbiter.html /// [`tokio_compat`]: https://crates.io/crates/tokio-compat /// /// # Arguments diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index b25a6f98..96c878e3 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -1,4 +1,4 @@ -//! See [`Service`](trait.Service.html) docs for information on this crate's foundational trait. +//! See [`Service`] docs for information on this crate's foundational trait. #![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity)] @@ -67,7 +67,7 @@ pub use self::transform::{apply, Transform}; /// ``` /// /// Sometimes it is not necessary to implement the Service trait. For example, the above service -/// could be rewritten as a simple function and passed to [fn_service](fn.fn_service.html). +/// could be rewritten as a simple function and passed to [fn_service](fn_service()). /// /// ```rust,ignore /// async fn my_service(req: u8) -> Result; diff --git a/actix-tracing/src/lib.rs b/actix-tracing/src/lib.rs index c011790b..b61ffac8 100644 --- a/actix-tracing/src/lib.rs +++ b/actix-tracing/src/lib.rs @@ -60,8 +60,6 @@ where } /// A `Transform` implementation that wraps services with a [`TracingService`]. -/// -/// [`TracingService`]: struct.TracingService.html pub struct TracingTransform { make_span: F, _p: PhantomData, diff --git a/string/src/lib.rs b/string/src/lib.rs index 553c8634..18cbc890 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -11,7 +11,7 @@ use bytes::Bytes; /// A UTF-8 encoded string with [`Bytes`] as a storage. /// -/// [`Bytes`]: https://docs.rs/bytes/0.5.3/bytes/struct.Bytes.html +/// [`Bytes`]: bytes::Bytes #[derive(Clone, Eq, Ord, PartialOrd, Default)] pub struct ByteString(Bytes);