From 0c1293079605b3d8e8a73db36ca9c1452f9ca829 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 28 Dec 2020 09:40:22 +0800 Subject: [PATCH 1/7] update to tokio 1.0 for actix-rt (#236) --- Cargo.toml | 2 +- actix-rt/CHANGES.md | 6 ++++-- actix-rt/Cargo.toml | 7 +------ actix-rt/src/arbiter.rs | 31 +++++++++++++---------------- actix-rt/src/builder.rs | 17 +++++++--------- actix-rt/src/lib.rs | 2 +- actix-rt/src/runtime.rs | 9 ++++----- actix-rt/src/system.rs | 20 +++++++++---------- actix-rt/tests/integration_tests.rs | 16 +++++++-------- 9 files changed, 49 insertions(+), 61 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f032478a..cea3ee3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ members = [ [patch.crates-io] actix-codec = { path = "actix-codec" } actix-connect = { path = "actix-connect" } -actix-rt = { path = "actix-rt" } +actix-rt = { git = "https://github.com/actix/actix-net.git", ref = "ba44ea7d0bafaf5fccb9a34003d503e1910943eepath" } actix-macros = { path = "actix-macros" } actix-server = { path = "actix-server" } actix-service = { path = "actix-service" } diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index c3479db1..8e73cef2 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -7,8 +7,10 @@ * Add `System::attach_to_tokio` method. [#173] ### Changed - -* Remove `'static` lifetime requirement for `Runtime::block_on` and `SystemRunner::block_on`. +* Update `tokio` dependency to `1` +* Rename `time` module `delay_for` to `sleep`, `delay_until` to `sleep_until`, `Delay` to `Sleep` to keep inline with tokio. +* Remove `'static` lifetime requirement for `Runtime::block_on` and `SystemRunner::block_on`. + These methods would accept &Self when calling. Remove `'static` lifetime requirement for `System::run` and `Builder::run`. `Arbiter::spawn` would panic when `System` is not in scope. [#207] diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index 57710a7f..eff206f2 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -18,9 +18,4 @@ path = "src/lib.rs" [dependencies] actix-macros = "0.1.0" -futures-channel = "0.3.7" -tokio = { version = "0.2.6", default-features = false, features = ["rt-core", "rt-util", "io-driver", "tcp", "uds", "udp", "time", "signal", "stream"] } - -[dev-dependencies] -futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] } -tokio = { version = "0.2.6", features = ["full"] } +tokio = { version = "1", features = ["rt", "net", "signal", "sync", "time"] } diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs index 3fe81b99..7aae7cd2 100644 --- a/actix-rt/src/arbiter.rs +++ b/actix-rt/src/arbiter.rs @@ -7,12 +7,11 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::{Context, Poll}; use std::{fmt, thread}; -use futures_channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}; -use futures_channel::oneshot::{channel, Canceled, Sender}; +use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}; +use tokio::sync::oneshot::{channel, error::RecvError as Canceled, Sender}; // use futures_util::stream::FuturesUnordered; // use tokio::task::JoinHandle; // use tokio::stream::StreamExt; -use tokio::stream::Stream; use tokio::task::LocalSet; use crate::runtime::Runtime; @@ -70,7 +69,7 @@ impl Default for Arbiter { impl Arbiter { pub(crate) fn new_system(local: &LocalSet) -> Self { - let (tx, rx) = unbounded(); + let (tx, rx) = unbounded_channel(); let arb = Arbiter::with_sender(tx); ADDR.with(|cell| *cell.borrow_mut() = Some(arb.clone())); @@ -98,7 +97,7 @@ impl Arbiter { /// Stop arbiter from continuing it's event loop. pub fn stop(&self) { - let _ = self.sender.unbounded_send(ArbiterCommand::Stop); + let _ = self.sender.send(ArbiterCommand::Stop); } /// Spawn new thread and run event loop in spawned thread. @@ -107,14 +106,14 @@ impl Arbiter { let id = COUNT.fetch_add(1, Ordering::Relaxed); let name = format!("actix-rt:worker:{}", id); let sys = System::current(); - let (tx, rx) = unbounded(); + let (tx, rx) = unbounded_channel(); let handle = thread::Builder::new() .name(name.clone()) .spawn({ let tx = tx.clone(); move || { - let mut rt = Runtime::new().expect("Can not create Runtime"); + let rt = Runtime::new().expect("Can not create Runtime"); let arb = Arbiter::with_sender(tx); STORAGE.with(|cell| cell.borrow_mut().clear()); @@ -126,7 +125,7 @@ impl Arbiter { // register arbiter let _ = System::current() .sys() - .unbounded_send(SystemCommand::RegisterArbiter(id, arb)); + .send(SystemCommand::RegisterArbiter(id, arb)); // start arbiter controller // run loop @@ -135,7 +134,7 @@ impl Arbiter { // unregister arbiter let _ = System::current() .sys() - .unbounded_send(SystemCommand::UnregisterArbiter(id)); + .send(SystemCommand::UnregisterArbiter(id)); } }) .unwrap_or_else(|err| { @@ -181,9 +180,7 @@ impl Arbiter { where F: Future + Send + Unpin + 'static, { - let _ = self - .sender - .unbounded_send(ArbiterCommand::Execute(Box::new(future))); + let _ = self.sender.send(ArbiterCommand::Execute(Box::new(future))); } /// Send a function to the Arbiter's thread, and execute it. Any result from the function @@ -194,7 +191,7 @@ impl Arbiter { { let _ = self .sender - .unbounded_send(ArbiterCommand::ExecuteFn(Box::new(move || { + .send(ArbiterCommand::ExecuteFn(Box::new(move || { f(); }))); } @@ -210,8 +207,8 @@ impl Arbiter { let (tx, rx) = channel(); let _ = self .sender - .unbounded_send(ArbiterCommand::ExecuteFn(Box::new(move || { - if !tx.is_canceled() { + .send(ArbiterCommand::ExecuteFn(Box::new(move || { + if !tx.is_closed() { let _ = tx.send(f()); } }))); @@ -328,7 +325,7 @@ impl Future for ArbiterController { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { loop { - match Pin::new(&mut self.rx).poll_next(cx) { + match Pin::new(&mut self.rx).poll_recv(cx) { Poll::Ready(None) => return Poll::Ready(()), Poll::Ready(Some(item)) => match item { ArbiterCommand::Stop => return Poll::Ready(()), @@ -393,7 +390,7 @@ impl Future for SystemArbiter { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { loop { - match Pin::new(&mut self.commands).poll_next(cx) { + match Pin::new(&mut self.commands).poll_recv(cx) { Poll::Ready(None) => return Poll::Ready(()), Poll::Ready(Some(cmd)) => match cmd { SystemCommand::Exit(code) => { diff --git a/actix-rt/src/builder.rs b/actix-rt/src/builder.rs index 83aed064..ff7b0e06 100644 --- a/actix-rt/src/builder.rs +++ b/actix-rt/src/builder.rs @@ -2,8 +2,8 @@ use std::borrow::Cow; use std::future::Future; use std::io; -use futures_channel::mpsc::unbounded; -use futures_channel::oneshot::{channel, Receiver}; +use tokio::sync::mpsc::unbounded_channel; +use tokio::sync::oneshot::{channel, Receiver}; use tokio::task::LocalSet; use crate::arbiter::{Arbiter, SystemArbiter}; @@ -72,7 +72,7 @@ impl Builder { fn create_async_runtime(self, local: &LocalSet) -> AsyncSystemRunner { let (stop_tx, stop) = channel(); - let (sys_sender, sys_receiver) = unbounded(); + let (sys_sender, sys_receiver) = unbounded_channel(); let system = System::construct(sys_sender, Arbiter::new_system(local), self.stop_on_panic); @@ -91,9 +91,9 @@ impl Builder { F: FnOnce(), { let (stop_tx, stop) = channel(); - let (sys_sender, sys_receiver) = unbounded(); + let (sys_sender, sys_receiver) = unbounded_channel(); - let mut rt = Runtime::new().unwrap(); + let rt = Runtime::new().unwrap(); let system = System::construct( sys_sender, @@ -157,7 +157,7 @@ impl SystemRunner { /// This function will start event loop and will finish once the /// `System::stop()` function is called. pub fn run(self) -> io::Result<()> { - let SystemRunner { mut rt, stop, .. } = self; + let SystemRunner { rt, stop, .. } = self; // run loop match rt.block_on(stop) { @@ -177,10 +177,7 @@ impl SystemRunner { /// Execute a future and wait for result. #[inline] - pub fn block_on(&mut self, fut: F) -> O - where - F: Future, - { + pub fn block_on(&self, fut: F) -> F::Output { self.rt.block_on(fut) } } diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index b2e23c0f..3fd94bf9 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -58,7 +58,7 @@ pub mod net { /// Utilities for tracking time. pub mod time { pub use tokio::time::Instant; - pub use tokio::time::{delay_for, delay_until, Delay}; pub use tokio::time::{interval, interval_at, Interval}; + pub use tokio::time::{sleep, sleep_until, Sleep}; pub use tokio::time::{timeout, Timeout}; } diff --git a/actix-rt/src/runtime.rs b/actix-rt/src/runtime.rs index 7ee02b02..a72f492c 100644 --- a/actix-rt/src/runtime.rs +++ b/actix-rt/src/runtime.rs @@ -18,10 +18,9 @@ impl Runtime { #[allow(clippy::new_ret_no_self)] /// Returns a new runtime initialized with default configuration values. pub fn new() -> io::Result { - let rt = runtime::Builder::new() + let rt = runtime::Builder::new_current_thread() .enable_io() .enable_time() - .basic_scheduler() .build()?; Ok(Runtime { @@ -48,7 +47,7 @@ impl Runtime { /// /// # fn dox() { /// // Create the runtime - /// let mut rt = Runtime::new().unwrap(); + /// let rt = Runtime::new().unwrap(); /// /// // Spawn a future onto the runtime /// rt.spawn(future::lazy(|_| { @@ -86,10 +85,10 @@ impl Runtime { /// /// The caller is responsible for ensuring that other spawned futures /// complete execution by calling `block_on` or `run`. - pub fn block_on(&mut self, f: F) -> F::Output + pub fn block_on(&self, f: F) -> F::Output where F: Future, { - self.local.block_on(&mut self.rt, f) + self.local.block_on(&self.rt, f) } } diff --git a/actix-rt/src/system.rs b/actix-rt/src/system.rs index 16b96439..1fbbc0ee 100644 --- a/actix-rt/src/system.rs +++ b/actix-rt/src/system.rs @@ -3,7 +3,7 @@ use std::future::Future; use std::io; use std::sync::atomic::{AtomicUsize, Ordering}; -use futures_channel::mpsc::UnboundedSender; +use tokio::sync::mpsc::UnboundedSender; use tokio::task::LocalSet; use crate::arbiter::{Arbiter, SystemCommand}; @@ -70,7 +70,7 @@ impl System { /// /// # Examples /// - /// ``` + /// ```rust,ignore /// use tokio::{runtime::Runtime, task::LocalSet}; /// use actix_rt::System; /// use futures_util::future::try_join_all; @@ -94,10 +94,9 @@ impl System { /// } /// /// - /// let mut runtime = tokio::runtime::Builder::new() - /// .core_threads(2) + /// let runtime = tokio::runtime::Builder::new_multi_thread() + /// .worker_threads(2) /// .enable_all() - /// .threaded_scheduler() /// .build() /// .unwrap(); /// @@ -140,7 +139,7 @@ impl System { /// /// # Examples /// - /// ``` + /// ```rust,ignore /// use tokio::runtime::Runtime; /// use actix_rt::System; /// use futures_util::future::try_join_all; @@ -164,10 +163,9 @@ impl System { /// } /// /// - /// let runtime = tokio::runtime::Builder::new() - /// .core_threads(2) + /// let runtime = tokio::runtime::Builder::new_multi_thread() + /// .worker_threads(2) /// .enable_all() - /// .threaded_scheduler() /// .build() /// .unwrap(); /// @@ -176,7 +174,7 @@ impl System { /// ``` pub fn attach_to_tokio( name: impl Into, - mut runtime: tokio::runtime::Runtime, + runtime: tokio::runtime::Runtime, rest_operations: Fut, ) -> R where @@ -233,7 +231,7 @@ impl System { /// Stop the system with a particular exit code. pub fn stop_with_code(&self, code: i32) { - let _ = self.sys.unbounded_send(SystemCommand::Exit(code)); + let _ = self.sys.send(SystemCommand::Exit(code)); } pub(crate) fn sys(&self) -> &UnboundedSender { diff --git a/actix-rt/tests/integration_tests.rs b/actix-rt/tests/integration_tests.rs index b3265476..12ceb4ef 100644 --- a/actix-rt/tests/integration_tests.rs +++ b/actix-rt/tests/integration_tests.rs @@ -5,7 +5,7 @@ fn await_for_timer() { let time = Duration::from_secs(2); let instant = Instant::now(); actix_rt::System::new("test_wait_timer").block_on(async move { - tokio::time::delay_for(time).await; + tokio::time::sleep(time).await; }); assert!( instant.elapsed() >= time, @@ -20,7 +20,7 @@ fn join_another_arbiter() { actix_rt::System::new("test_join_another_arbiter").block_on(async move { let mut arbiter = actix_rt::Arbiter::new(); arbiter.send(Box::pin(async move { - tokio::time::delay_for(time).await; + tokio::time::sleep(time).await; actix_rt::Arbiter::current().stop(); })); arbiter.join().unwrap(); @@ -35,7 +35,7 @@ fn join_another_arbiter() { let mut arbiter = actix_rt::Arbiter::new(); arbiter.exec_fn(move || { actix_rt::spawn(async move { - tokio::time::delay_for(time).await; + tokio::time::sleep(time).await; actix_rt::Arbiter::current().stop(); }); }); @@ -50,7 +50,7 @@ fn join_another_arbiter() { actix_rt::System::new("test_join_another_arbiter").block_on(async move { let mut arbiter = actix_rt::Arbiter::new(); arbiter.send(Box::pin(async move { - tokio::time::delay_for(time).await; + tokio::time::sleep(time).await; actix_rt::Arbiter::current().stop(); })); arbiter.stop(); @@ -104,17 +104,17 @@ fn non_static_block_on() { let string = String::from("test_str"); let str = string.as_str(); - let mut sys = actix_rt::System::new("borrow some"); + let sys = actix_rt::System::new("borrow some"); sys.block_on(async { - actix_rt::time::delay_for(Duration::from_millis(1)).await; + actix_rt::time::sleep(Duration::from_millis(1)).await; assert_eq!("test_str", str); }); - let mut rt = actix_rt::Runtime::new().unwrap(); + let rt = actix_rt::Runtime::new().unwrap(); rt.block_on(async { - actix_rt::time::delay_for(Duration::from_millis(1)).await; + actix_rt::time::sleep(Duration::from_millis(1)).await; assert_eq!("test_str", str); }); From d684128831dbaaf86bbd42639dad34a776d91907 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 28 Dec 2020 01:48:19 +0000 Subject: [PATCH 2/7] fix rt override --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cea3ee3a..b3274564 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ members = [ [patch.crates-io] actix-codec = { path = "actix-codec" } actix-connect = { path = "actix-connect" } -actix-rt = { git = "https://github.com/actix/actix-net.git", ref = "ba44ea7d0bafaf5fccb9a34003d503e1910943eepath" } +actix-rt = { git = "https://github.com/actix/actix-net.git", ref = "ba44ea7d0bafaf5fccb9a34003d503e1910943ee" } actix-macros = { path = "actix-macros" } actix-server = { path = "actix-server" } actix-service = { path = "actix-service" } From 3d3bd60368f72ab09347b7f82e93b979204757d0 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 28 Dec 2020 01:53:11 +0000 Subject: [PATCH 3/7] fix rt override --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b3274564..61280183 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ members = [ [patch.crates-io] actix-codec = { path = "actix-codec" } actix-connect = { path = "actix-connect" } -actix-rt = { git = "https://github.com/actix/actix-net.git", ref = "ba44ea7d0bafaf5fccb9a34003d503e1910943ee" } +actix-rt = { git = "https://github.com/actix/actix-net.git", rev = "ba44ea7d0bafaf5fccb9a34003d503e1910943ee" } actix-macros = { path = "actix-macros" } actix-server = { path = "actix-server" } actix-service = { path = "actix-service" } From f48e3f4cb0cf5779b43d5ec465a646253d96057f Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 28 Dec 2020 01:58:31 +0000 Subject: [PATCH 4/7] prepare release for rt and service --- actix-rt/CHANGES.md | 18 ++++++++++-------- actix-rt/Cargo.toml | 4 ++-- actix-rt/src/lib.rs | 3 ++- actix-service/CHANGES.md | 8 +++++++- actix-service/Cargo.toml | 7 +++++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 8e73cef2..35409616 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -2,23 +2,25 @@ ## Unreleased - 2020-xx-xx -### Added +## 2.0.0-beta.1 - 2020-12-28 +### Added * Add `System::attach_to_tokio` method. [#173] ### Changed -* Update `tokio` dependency to `1` -* Rename `time` module `delay_for` to `sleep`, `delay_until` to `sleep_until`, `Delay` to `Sleep` to keep inline with tokio. +* Update `tokio` dependency to `1.0`. [#236] +* Rename `time` module `delay_for` to `sleep`, `delay_until` to `sleep_until`, `Delay` to `Sleep` + to stay aligned with Tokio's naming. [#236] * Remove `'static` lifetime requirement for `Runtime::block_on` and `SystemRunner::block_on`. - These methods would accept &Self when calling. - Remove `'static` lifetime requirement for `System::run` and `Builder::run`. - `Arbiter::spawn` would panic when `System` is not in scope. [#207] + * These methods now accept `&self` when calling. [#236] +* Remove `'static` lifetime requirement for `System::run` and `Builder::run`. [#236] +* `Arbiter::spawn` now panics when `System` is not in scope. [#207] ### Fixed - -* Fix work load issue by removing `PENDDING` thread local. [#207] +* Fix work load issue by removing `PENDING` thread local. [#207] [#207]: https://github.com/actix/actix-net/pull/207 +[#236]: https://github.com/actix/actix-net/pull/236 ## [1.1.1] - 2020-04-30 diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index eff206f2..317345d4 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "actix-rt" -version = "1.1.1" +version = "2.0.0-beta.1" authors = ["Nikolay Kim "] -description = "Actix runtime" +description = "Tokio-based single-thread async runtime for the Actix ecosystem" keywords = ["network", "framework", "async", "futures"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-net.git" diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index 3fd94bf9..440fa33c 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -1,4 +1,5 @@ -//! A runtime implementation that runs everything on the current thread. +//! Tokio-based single-thread async runtime for the Actix ecosystem. + #![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity)] #![doc(html_logo_url = "https://actix.rs/img/logo.png")] diff --git a/actix-service/CHANGES.md b/actix-service/CHANGES.md index 82c5adb3..1cbf414e 100644 --- a/actix-service/CHANGES.md +++ b/actix-service/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2020-xx-xx + + +## 2.0.0-beta.1 - 2020-12-28 * `Service`, other traits, and many type signatures now take the the request type as a type parameter instead of an associated type. [#232] * Add `always_ready!` and `forward_ready!` macros. [#233] @@ -19,7 +22,10 @@ ### Fixed -* Removed unsound custom Cell implementation that allowed obtaining several mutable references to the same data, which is undefined behavior in Rust and could lead to violations of memory safety. External code could obtain several mutable references to the same data through service combinators. Attempts to acquire several mutable references to the same data will instead result in a panic. +* Removed unsound custom Cell implementation that allowed obtaining several mutable references to + the same data, which is undefined behavior in Rust and could lead to violations of memory safety. External code could obtain several mutable references to the same data through + service combinators. Attempts to acquire several mutable references to the same data will instead + result in a panic. ## [1.0.5] - 2020-01-16 diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index c08bb169..708fb5e6 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -1,7 +1,10 @@ [package] name = "actix-service" -version = "1.0.6" -authors = ["Nikolay Kim "] +version = "2.0.0-beta.1" +authors = [ + "Nikolay Kim ", + "Rob Ede ", +] description = "Service trait and combinators for representing asynchronous request/response operations." keywords = ["network", "framework", "async", "futures", "service"] homepage = "https://actix.rs" From 2ee8f45f5dc66486d071b13b1acc17c150568823 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 28 Dec 2020 11:16:37 +0800 Subject: [PATCH 5/7] update actix-codec and actix-utils to tokio 1.0 (#237) --- Cargo.toml | 6 +++--- actix-codec/CHANGES.md | 5 ++++- actix-codec/Cargo.toml | 12 ++++++------ actix-codec/src/bcodec.rs | 2 +- actix-codec/src/framed.rs | 37 +++++++++++++++++++------------------ actix-codec/src/lib.rs | 3 ++- actix-utils/CHANGES.md | 1 + actix-utils/Cargo.toml | 4 ++-- actix-utils/src/timeout.rs | 29 +++++++++++++++-------------- 9 files changed, 53 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 61280183..d46b6283 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,16 +16,16 @@ members = [ ] [patch.crates-io] -actix-codec = { path = "actix-codec" } +actix-codec = { git = "https://github.com/actix/actix-net.git", rev = "ba44ea7d0bafaf5fccb9a34003d503e1910943ee" } actix-connect = { path = "actix-connect" } actix-rt = { git = "https://github.com/actix/actix-net.git", rev = "ba44ea7d0bafaf5fccb9a34003d503e1910943ee" } actix-macros = { path = "actix-macros" } actix-server = { path = "actix-server" } -actix-service = { path = "actix-service" } +actix-service = { git = "https://github.com/actix/actix-net.git", rev = "ba44ea7d0bafaf5fccb9a34003d503e1910943ee" } actix-testing = { path = "actix-testing" } actix-threadpool = { path = "actix-threadpool" } actix-tls = { path = "actix-tls" } actix-tracing = { path = "actix-tracing" } -actix-utils = { path = "actix-utils" } +actix-utils = { git = "https://github.com/actix/actix-net.git", rev = "ba44ea7d0bafaf5fccb9a34003d503e1910943ee" } actix-router = { path = "router" } bytestring = { path = "string" } diff --git a/actix-codec/CHANGES.md b/actix-codec/CHANGES.md index cd4424d0..3d82775a 100644 --- a/actix-codec/CHANGES.md +++ b/actix-codec/CHANGES.md @@ -1,7 +1,10 @@ # Changes ## Unreleased - 2020-xx-xx -* Upgrade `pin-project` to `1.0`. +* Replace `pin-project` with `pin-project-lite`. +* Upgrade `tokio` dependency to `1`. +* Upgrade `tokio-util` dependency to `0.6`. +* Upgrade `bytes` dependency to `1`. ## 0.3.0 - 2020-08-23 * No changes from beta 2. diff --git a/actix-codec/Cargo.toml b/actix-codec/Cargo.toml index 1214945a..e901efd5 100644 --- a/actix-codec/Cargo.toml +++ b/actix-codec/Cargo.toml @@ -17,10 +17,10 @@ path = "src/lib.rs" [dependencies] bitflags = "1.2.1" -bytes = "0.5.2" -futures-core = { version = "0.3.4", default-features = false } -futures-sink = { version = "0.3.4", default-features = false } +bytes = "1" +futures-core = { version = "0.3.7", default-features = false } +futures-sink = { version = "0.3.7", default-features = false } log = "0.4" -pin-project = "1.0.0" -tokio = { version = "0.2.5", default-features = false } -tokio-util = { version = "0.3.1", default-features = false, features = ["codec"] } +pin-project-lite = "0.2" +tokio = "1" +tokio-util = { version = "0.6", features = ["codec", "io"] } diff --git a/actix-codec/src/bcodec.rs b/actix-codec/src/bcodec.rs index 045b20a2..b06279ea 100644 --- a/actix-codec/src/bcodec.rs +++ b/actix-codec/src/bcodec.rs @@ -14,7 +14,7 @@ impl Encoder for BytesCodec { #[inline] fn encode(&mut self, item: Bytes, dst: &mut BytesMut) -> Result<(), Self::Error> { - dst.extend_from_slice(item.bytes()); + dst.extend_from_slice(item.chunk()); Ok(()) } } diff --git a/actix-codec/src/framed.rs b/actix-codec/src/framed.rs index 844f20d8..cf2297dc 100644 --- a/actix-codec/src/framed.rs +++ b/actix-codec/src/framed.rs @@ -5,7 +5,6 @@ use std::{fmt, io}; use bytes::{Buf, BytesMut}; use futures_core::{ready, Stream}; use futures_sink::Sink; -use pin_project::pin_project; use crate::{AsyncRead, AsyncWrite, Decoder, Encoder}; @@ -21,22 +20,23 @@ bitflags::bitflags! { } } -/// A unified `Stream` and `Sink` interface to an underlying I/O object, using -/// the `Encoder` and `Decoder` traits to encode and decode frames. -/// -/// Raw I/O objects work with byte sequences, but higher-level code usually -/// wants to batch these into meaningful chunks, called "frames". This -/// method layers framing on top of an I/O object, by using the `Encoder`/`Decoder` -/// traits to handle encoding and decoding of message frames. Note that -/// the incoming and outgoing frame types may be distinct. -#[pin_project] -pub struct Framed { - #[pin] - io: T, - codec: U, - flags: Flags, - read_buf: BytesMut, - write_buf: BytesMut, +pin_project_lite::pin_project! { + /// A unified `Stream` and `Sink` interface to an underlying I/O object, using + /// the `Encoder` and `Decoder` traits to encode and decode frames. + /// + /// Raw I/O objects work with byte sequences, but higher-level code usually + /// wants to batch these into meaningful chunks, called "frames". This + /// method layers framing on top of an I/O object, by using the `Encoder`/`Decoder` + /// traits to handle encoding and decoding of message frames. Note that + /// the incoming and outgoing frame types may be distinct. + pub struct Framed { + #[pin] + io: T, + codec: U, + flags: Flags, + read_buf: BytesMut, + write_buf: BytesMut, + } } impl Framed @@ -220,7 +220,8 @@ impl Framed { if remaining < LW { this.read_buf.reserve(HW - remaining) } - let cnt = match this.io.poll_read_buf(cx, &mut this.read_buf) { + + let cnt = match tokio_util::io::poll_read_buf(this.io, cx, this.read_buf) { Poll::Pending => return Poll::Pending, Poll::Ready(Err(e)) => return Poll::Ready(Some(Err(e.into()))), Poll::Ready(Ok(cnt)) => cnt, diff --git a/actix-codec/src/lib.rs b/actix-codec/src/lib.rs index 8c346052..9e875409 100644 --- a/actix-codec/src/lib.rs +++ b/actix-codec/src/lib.rs @@ -18,5 +18,6 @@ mod framed; pub use self::bcodec::BytesCodec; pub use self::framed::{Framed, FramedParts}; -pub use tokio::io::{AsyncRead, AsyncWrite}; +pub use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; pub use tokio_util::codec::{Decoder, Encoder}; +pub use tokio_util::io::poll_read_buf; diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index b4d59ed0..b112d8b1 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -1,6 +1,7 @@ # Changes ## Unreleased - 2020-xx-xx +* Update `bytes` dependency to `1`. * Use `pin-project-lite` to replace `pin-project`. [#229] * Remove `condition`,`either`,`inflight`,`keepalive`,`oneshot`,`order`,`stream` and `time` mods. [#229] diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index fb7ed151..3ed4a518 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -17,8 +17,8 @@ path = "src/lib.rs" [dependencies] actix-codec = "0.3.0" -actix-rt = "1.1.1" -actix-service = "1.0.6" +actix-rt = "2.0.0-beta.1" +actix-service = "2.0.0-beta.1" futures-core = { version = "0.3.7", default-features = false } futures-sink = { version = "0.3.7", default-features = false } diff --git a/actix-utils/src/timeout.rs b/actix-utils/src/timeout.rs index a27e9ffb..612c3cb4 100644 --- a/actix-utils/src/timeout.rs +++ b/actix-utils/src/timeout.rs @@ -9,7 +9,7 @@ use core::pin::Pin; use core::task::{Context, Poll}; use core::{fmt, time}; -use actix_rt::time::{delay_for, Delay}; +use actix_rt::time::{sleep, Sleep}; use actix_service::{IntoService, Service, Transform}; use pin_project_lite::pin_project; @@ -85,8 +85,8 @@ where { type Response = S::Response; type Error = TimeoutError; - type InitError = E; type Transform = TimeoutService; + type InitError = E; type Future = TimeoutFuture; fn new_transform(&self, service: S) -> Self::Future { @@ -157,7 +157,7 @@ where fn call(&mut self, request: Req) -> Self::Future { TimeoutServiceResponse { fut: self.service.call(request), - sleep: delay_for(self.timeout), + sleep: sleep(self.timeout), } } } @@ -171,7 +171,8 @@ pin_project! { { #[pin] fut: S::Future, - sleep: Delay, + #[pin] + sleep: Sleep, } } @@ -193,20 +194,18 @@ where } // Now check the sleep - Pin::new(this.sleep) - .poll(cx) - .map(|_| Err(TimeoutError::Timeout)) + this.sleep.poll(cx).map(|_| Err(TimeoutError::Timeout)) } } #[cfg(test)] mod tests { - use std::task::Poll; - use std::time::Duration; + use core::task::Poll; + use core::time::Duration; use super::*; use actix_service::{apply, fn_factory, Service, ServiceFactory}; - use futures_util::future::{ok, FutureExt, LocalBoxFuture}; + use futures_core::future::LocalBoxFuture; struct SleepService(Duration); @@ -218,9 +217,11 @@ mod tests { actix_service::always_ready!(); fn call(&mut self, _: ()) -> Self::Future { - actix_rt::time::delay_for(self.0) - .then(|_| ok::<_, ()>(())) - .boxed_local() + let sleep = actix_rt::time::sleep(self.0); + Box::pin(async move { + sleep.await; + Ok(()) + }) } } @@ -249,7 +250,7 @@ mod tests { let timeout = apply( Timeout::new(resolution), - fn_factory(|| ok::<_, ()>(SleepService(wait_time))), + fn_factory(|| async { Ok::<_, ()>(SleepService(wait_time)) }), ); let mut srv = timeout.new_service(&()).await.unwrap(); From e4a44b77e673c8fad5fcd8eed259618d28ac5c8c Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 28 Dec 2020 03:24:43 +0000 Subject: [PATCH 6/7] prepare codec release 0.4.0-beta.1 --- actix-codec/CHANGES.md | 31 +++++++++++++++++++------------ actix-codec/Cargo.toml | 4 ++-- actix-codec/src/lib.rs | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/actix-codec/CHANGES.md b/actix-codec/CHANGES.md index 3d82775a..0c26c085 100644 --- a/actix-codec/CHANGES.md +++ b/actix-codec/CHANGES.md @@ -1,17 +1,25 @@ # Changes ## Unreleased - 2020-xx-xx -* Replace `pin-project` with `pin-project-lite`. -* Upgrade `tokio` dependency to `1`. -* Upgrade `tokio-util` dependency to `0.6`. -* Upgrade `bytes` dependency to `1`. + + +## 0.4.0-beta.1 - 2020-12-28 +* Replace `pin-project` with `pin-project-lite`. [#237] +* Upgrade `tokio` dependency to `1`. [#237] +* Upgrade `tokio-util` dependency to `0.6`. [#237] +* Upgrade `bytes` dependency to `1`. [#237] + +[#237]: https://github.com/actix/actix-net/pull/237 + ## 0.3.0 - 2020-08-23 * No changes from beta 2. + ## 0.3.0-beta.2 - 2020-08-19 * Remove unused type parameter from `Framed::replace_codec`. + ## 0.3.0-beta.1 - 2020-08-19 * Use `.advance()` instead of `.split_to()`. * Upgrade `tokio-util` to `0.3`. @@ -21,32 +29,31 @@ * Add method on `Framed` to get a pinned reference to the underlying I/O. * Add method on `Framed` check emptiness of read buffer. -## [0.2.0] - 2019-12-10 +## 0.2.0 - 2019-12-10 * Use specific futures dependencies -## [0.2.0-alpha.4] +## 0.2.0-alpha.4 * Fix buffer remaining capacity calculation -## [0.2.0-alpha.3] +## 0.2.0-alpha.3 * Use tokio 0.2 - * Fix low/high watermark for write/read buffers -## [0.2.0-alpha.2] +## 0.2.0-alpha.2 * Migrated to `std::future` -## [0.1.2] - 2019-03-27 +## 0.1.2 - 2019-03-27 * Added `Framed::map_io()` method. -## [0.1.1] - 2019-03-06 +## 0.1.1 - 2019-03-06 * Added `FramedParts::with_read_buffer()` method. -## [0.1.0] - 2018-12-09 +## 0.1.0 - 2018-12-09 * Move codec to separate crate diff --git a/actix-codec/Cargo.toml b/actix-codec/Cargo.toml index e901efd5..d0f6646d 100644 --- a/actix-codec/Cargo.toml +++ b/actix-codec/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "actix-codec" -version = "0.3.0" +version = "0.4.0-beta.1" authors = ["Nikolay Kim "] -description = "Codec utilities for working with framed protocols." +description = "Codec utilities for working with framed protocols" keywords = ["network", "framework", "async", "futures"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-net.git" diff --git a/actix-codec/src/lib.rs b/actix-codec/src/lib.rs index 9e875409..dec30ba6 100644 --- a/actix-codec/src/lib.rs +++ b/actix-codec/src/lib.rs @@ -1,4 +1,4 @@ -//! Utilities for encoding and decoding frames. +//! Codec utilities for working with framed protocols. //! //! Contains adapters to go from streams of bytes, [`AsyncRead`] and //! [`AsyncWrite`], to framed streams implementing [`Sink`] and [`Stream`]. From a09f9abfcb712ffbf61a90c80a258281a739a88a Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 28 Dec 2020 03:32:28 +0000 Subject: [PATCH 7/7] prepare utils release 3.0.0-beta.1 --- actix-utils/CHANGES.md | 213 +++++++++++++------------------------ actix-utils/Cargo.toml | 6 +- actix-utils/src/lib.rs | 2 +- actix-utils/src/mpsc.rs | 1 + actix-utils/src/timeout.rs | 3 +- 5 files changed, 77 insertions(+), 148 deletions(-) diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index b112d8b1..6c7025b5 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -1,227 +1,156 @@ # Changes ## Unreleased - 2020-xx-xx -* Update `bytes` dependency to `1`. + + +## 3.0.0-beta.1 - 2020-12-28 +* Update `bytes` dependency to `1`. [#237] * Use `pin-project-lite` to replace `pin-project`. [#229] * Remove `condition`,`either`,`inflight`,`keepalive`,`oneshot`,`order`,`stream` and `time` mods. [#229] [#229]: https://github.com/actix/actix-net/pull/229 +[#237]: https://github.com/actix/actix-net/pull/237 + ## 2.0.0 - 2020-08-23 * No changes from beta 1. + ## 2.0.0-beta.1 - 2020-08-19 * Upgrade `tokio-util` to `0.3`. * Remove unsound custom Cell and use `std::cell::RefCell` instead, as well as `actix-service`. * Rename method to correctly spelled `LocalWaker::is_registered`. -## [1.0.6] - 2020-01-08 -* Add `Clone` impl for `condition::Waiter` +## 1.0.6 - 2020-01-08 +* Add `Clone` impl for `condition::Waiter`. -## [1.0.5] - 2020-01-08 +## 1.0.5 - 2020-01-08 * Add `Condition` type. - * Add `Pool` of one-shot's. -## [1.0.4] - 2019-12-20 +## 1.0.4 - 2019-12-20 * Add methods to check `LocalWaker` registration state. -## [1.0.3] - 2019-12-11 +## 1.0.3 - 2019-12-11 * Revert InOrder service changes -## [1.0.2] - 2019-12-11 -* Allow to create `framed::Dispatcher` with custom `mpsc::Receiver` +## 1.0.2 - 2019-12-11 +* Allow to create `framed::Dispatcher` with custom `mpsc::Receiver`. +* Add `oneshot::Sender::is_canceled()` method. -* Add `oneshot::Sender::is_canceled()` method -## [1.0.1] - 2019-12-11 +## 1.0.1 - 2019-12-11 +* Optimize InOrder service. -* Optimize InOrder service -## [1.0.0] - 2019-12-11 +## 1.0.0 - 2019-12-11 +* Simplify oneshot and mpsc implementations. -* Simplify oneshot and mpsc implementations -## [1.0.0-alpha.3] - 2019-12-07 +## 1.0.0-alpha.3 - 2019-12-07 +* Migrate to tokio 0.2. +* Fix oneshot. -* Migrate to tokio 0.2 -* Fix oneshot +## 1.0.0-alpha.2 - 2019-12-02 +* Migrate to `std::future`. -## [1.0.0-alpha.2] - 2019-12-02 - -* Migrate to `std::future` - -## [0.4.7] - 2019-10-14 +## 0.4.7 - 2019-10-14 * Re-register task on every framed transport poll. -## [0.4.6] - 2019-10-08 - +## 0.4.6 - 2019-10-08 * Refactor `Counter` type. register current task in available method. -## [0.4.5] - 2019-07-19 - -### Removed - -* Deprecated `CloneableService` as it is not safe +## 0.4.5 - 2019-07-19 +* Deprecated `CloneableService` as it is not safe. -## [0.4.4] - 2019-07-17 - -### Changed - -* Undeprecate `FramedTransport` as it is actually useful +## 0.4.4 - 2019-07-17 +* Undeprecate `FramedTransport` as it is actually useful. -## [0.4.3] - 2019-07-17 - -### Deprecated - -* Deprecate `CloneableService` as it is not safe and in general not very useful - -* Deprecate `FramedTransport` in favor of `actix-ioframe` +## 0.4.3 - 2019-07-17 +* Deprecate `CloneableService` as it is not safe and in general not very useful. +* Deprecate `FramedTransport` in favor of `actix-ioframe`. -## [0.4.2] - 2019-06-26 - -### Fixed - -* Do not block on sink drop for FramedTransport +## 0.4.2 - 2019-06-26 +* Do not block on sink drop for FramedTransport. -## [0.4.1] - 2019-05-15 - -### Changed - -* Change `Either` constructor +## 0.4.1 - 2019-05-15 +* Change `Either` constructor. -## [0.4.0] - 2019-05-11 +## 0.4.0 - 2019-05-11 +* Change `Either` to handle two nexted services. +* Upgrade actix-service 0.4. +* Removed framed related services. +* Removed stream related services. -### Changed - -* Change `Either` to handle two nexted services - -* Upgrade actix-service 0.4 - -### Deleted - -* Framed related services - -* Stream related services - -## [0.3.5] - 2019-04-04 - -### Added +## 0.3.5 - 2019-04-04 * Allow to send messages to `FramedTransport` via mpsc channel. - -### Changed - -* Remove 'static constraint from Clonable service +* Remove `'static` constraint from Clonable service. -## [0.3.4] - 2019-03-12 - -### Changed - +## 0.3.4 - 2019-03-12 * `TimeoutService`, `InOrderService`, `InFlightService` accepts generic IntoService services. - -### Fixed - -* Fix `InFlightService::poll_ready()` nested service readiness check - -* Fix `InOrderService::poll_ready()` nested service readiness check +* Fix `InFlightService::poll_ready()` nested service readiness check. +* Fix `InOrderService::poll_ready()` nested service readiness check. -## [0.3.3] - 2019-03-09 - -### Changed - -* Revert IntoFuture change - -* Add generic config param for IntoFramed and TakeOne new services +## 0.3.3 - 2019-03-09 +* Revert IntoFuture change. +* Add generic config param for IntoFramed and TakeOne new services. -## [0.3.2] - 2019-03-04 +## 0.3.2 - 2019-03-04 +* Use IntoFuture for new services. -### Changed - -* Use IntoFuture for new services +## 0.3.1 - 2019-03-04 +* Use new type of transform trait. -## [0.3.1] - 2019-03-04 - -### Changed - -* Use new type of transform trait - - -## [0.3.0] - 2019-03-02 - -### Changed - +## 0.3.0 - 2019-03-02 * Use new `NewService` trait - * BoxedNewService` and `BoxedService` types moved to actix-service crate. -## [0.2.4] - 2019-02-21 - -### Changed - +## 0.2.4 - 2019-02-21 * Custom `BoxedNewService` implementation. -## [0.2.3] - 2019-02-21 - -### Added - -* Add `BoxedNewService` and `BoxedService` +## 0.2.3 - 2019-02-21 +* Add `BoxedNewService` and `BoxedService`. -## [0.2.2] - 2019-02-11 - -### Added - -* Add `Display` impl for `TimeoutError` - -* Add `Display` impl for `InOrderError` +## 0.2.2 - 2019-02-11 +* Add `Display` impl for `TimeoutError`. +* Add `Display` impl for `InOrderError`. -## [0.2.1] - 2019-02-06 - -### Added - +## 0.2.1 - 2019-02-06 * Add `InOrder` service. the service yields responses as they become available, in the order that their originating requests were submitted to the service. - -### Changed - -* Convert `Timeout` and `InFlight` services to a transforms +* Convert `Timeout` and `InFlight` services to a transforms. -## [0.2.0] - 2019-02-01 - -* Fix framed transport error handling - -* Added Clone impl for Either service - -* Added Clone impl for Timeout service factory - -* Added Service and NewService for Stream dispatcher - -* Switch to actix-service 0.2 +## 0.2.0 - 2019-02-01 +* Fix framed transport error handling. +* Added Clone impl for Either service. +* Added Clone impl for Timeout service factory. +* Added Service and NewService for Stream dispatcher. +* Switch to actix-service 0.2. -## [0.1.0] - 2018-12-09 - -* Move utils services to separate crate +## 0.1.0 - 2018-12-09 +* Move utils services to separate crate. diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index 3ed4a518..3dded4f0 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "actix-utils" -version = "2.0.0" +version = "3.0.0-beta.1" authors = ["Nikolay Kim "] -description = "Various network related services and utilities for the Actix ecosystem." +description = "Various network related services and utilities for the Actix ecosystem" keywords = ["network", "framework", "async", "futures"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-net.git" @@ -16,7 +16,7 @@ name = "actix_utils" path = "src/lib.rs" [dependencies] -actix-codec = "0.3.0" +actix-codec = "0.4.0-beta.1" actix-rt = "2.0.0-beta.1" actix-service = "2.0.0-beta.1" diff --git a/actix-utils/src/lib.rs b/actix-utils/src/lib.rs index 4c4f019c..5c10bac6 100644 --- a/actix-utils/src/lib.rs +++ b/actix-utils/src/lib.rs @@ -1,4 +1,4 @@ -//! Actix utils - various helper services +//! Various network related services and utilities for the Actix ecosystem. #![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity)] diff --git a/actix-utils/src/mpsc.rs b/actix-utils/src/mpsc.rs index 2299dedb..2f2b3f04 100644 --- a/actix-utils/src/mpsc.rs +++ b/actix-utils/src/mpsc.rs @@ -1,4 +1,5 @@ //! A multi-producer, single-consumer, futures-aware, FIFO queue. + use core::any::Any; use core::cell::RefCell; use core::fmt; diff --git a/actix-utils/src/timeout.rs b/actix-utils/src/timeout.rs index 612c3cb4..85e328b9 100644 --- a/actix-utils/src/timeout.rs +++ b/actix-utils/src/timeout.rs @@ -1,7 +1,6 @@ //! Service that applies a timeout to requests. //! -//! If the response does not complete within the specified timeout, the response -//! will be aborted. +//! If the response does not complete within the specified timeout, the response will be aborted. use core::future::Future; use core::marker::PhantomData;