From 23ecc2b5eb36d484f7bd7d16e23b71c48255f5f3 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 6 Nov 2019 14:11:24 -0800 Subject: [PATCH] [0.1.x] chore: remove old async-await support (#1742) ## Motivation Currently, the tests for `tokio` 0.1's async-await support build against a fairly old nightly from Rust 1.36. Upstream changes to a transitive dependency introduced a use of `MaybeUninit`, which is feature flagged on this nightly. This resultedin [0.1.x builds breaking][1]. The `tokio` 0.1 async-await support has not been maintained, in favour of working on 0.2. It currently uses severely outdated versions of the async-await APIs (including the `await!` macro). Anyone using async-await with Tokio is almsot certainly on 0.2 by now. ## Solution Since the 0.1 async-await APIs are both unused and unmaintained, this branch deletes them. [1]: https://dev.azure.com/tokio-rs/Tokio/_build/results?buildId=3174&view=logs&jobId=ba363064-0d45-526e-6c63-c7e816804fbe&taskId=3aff0ee6-e312-56d4-f5d3-d804e6c343c3&lineStart=83&lineEnd=87&colStart=1&colEnd=1 Signed-off-by: Eliza Weisman --- async-await/.cargo/config | 2 - async-await/Cargo.toml | 49 ------------ async-await/README.md | 5 -- async-await/src/chat.rs | 131 --------------------------------- async-await/src/echo_client.rs | 50 ------------- async-await/src/echo_server.rs | 42 ----------- async-await/src/hyper.rs | 29 -------- async-await/tests/macros.rs | 22 ------ azure-pipelines.yml | 8 -- ci/azure-test-nightly.yml | 19 ----- 10 files changed, 357 deletions(-) delete mode 100644 async-await/.cargo/config delete mode 100644 async-await/Cargo.toml delete mode 100644 async-await/README.md delete mode 100644 async-await/src/chat.rs delete mode 100644 async-await/src/echo_client.rs delete mode 100644 async-await/src/echo_server.rs delete mode 100644 async-await/src/hyper.rs delete mode 100644 async-await/tests/macros.rs delete mode 100644 ci/azure-test-nightly.yml diff --git a/async-await/.cargo/config b/async-await/.cargo/config deleted file mode 100644 index ec6a5d0a2..000000000 --- a/async-await/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target-dir = "../target" diff --git a/async-await/Cargo.toml b/async-await/Cargo.toml deleted file mode 100644 index e605da602..000000000 --- a/async-await/Cargo.toml +++ /dev/null @@ -1,49 +0,0 @@ -[package] -name = "examples" -edition = "2018" -version = "0.1.0" -authors = ["Carl Lerche "] -license = "MIT" - -# Break out of the parent workspace -[workspace] - -[[bin]] -name = "chat" -path = "src/chat.rs" - -[[bin]] -name = "echo_client" -path = "src/echo_client.rs" - -[[bin]] -name = "echo_server" -path = "src/echo_server.rs" - -[[bin]] -name = "hyper" -path = "src/hyper.rs" - -[dependencies] -tokio = { version = "0.1.18", features = ["async-await-preview"] } -futures = "0.1.23" -bytes = "0.4.9" -hyper = "0.12.8" - -# Avoid using crates.io for Tokio dependencies -[patch.crates-io] -tokio = { path = "../tokio" } -tokio-codec = { path = "../tokio-codec" } -tokio-current-thread = { path = "../tokio-current-thread" } -tokio-executor = { path = "../tokio-executor" } -tokio-fs = { path = "../tokio-fs" } -tokio-futures = { path = "../tokio-futures" } -tokio-io = { path = "../tokio-io" } -tokio-reactor = { path = "../tokio-reactor" } -tokio-signal = { path = "../tokio-signal" } -tokio-tcp = { path = "../tokio-tcp" } -tokio-threadpool = { path = "../tokio-threadpool" } -tokio-timer = { path = "../tokio-timer" } -tokio-tls = { path = "../tokio-tls" } -tokio-udp = { path = "../tokio-udp" } -tokio-uds = { path = "../tokio-uds" } diff --git a/async-await/README.md b/async-await/README.md deleted file mode 100644 index bd360f0e1..000000000 --- a/async-await/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Tokio async/await examples - -These are a separate crate in order to work around some cargo bugs. It also -allows `[patch]` to be used in `Cargo.toml` to ensure the correct lib versions -are being pulled in. diff --git a/async-await/src/chat.rs b/async-await/src/chat.rs deleted file mode 100644 index d0576f529..000000000 --- a/async-await/src/chat.rs +++ /dev/null @@ -1,131 +0,0 @@ -#![feature(await_macro, async_await)] - -use tokio::await; -use tokio::codec::{LinesCodec, Decoder}; -use tokio::net::{TcpListener, TcpStream}; -use tokio::prelude::*; - -use futures::sync::mpsc; - -use std::collections::HashMap; -use std::io; -use std::net::SocketAddr; -use std::sync::{Arc, Mutex}; - -/// Shorthand for the transmit half of the message channel. -type Tx = mpsc::UnboundedSender; - -struct Shared { - peers: HashMap, -} - -impl Shared { - /// Create a new, empty, instance of `Shared`. - fn new() -> Self { - Shared { - peers: HashMap::new(), - } - } -} - -async fn process(stream: TcpStream, state: Arc>) -> io::Result<()> { - let addr = stream.peer_addr().unwrap(); - let mut lines = LinesCodec::new().framed(stream); - - // Extract the peer's name - let name = match await!(lines.next()) { - Some(name) => name?, - None => { - // Disconnected early - return Ok(()); - } - }; - - println!("`{}` is joining the chat", name); - - let (tx, mut rx) = mpsc::unbounded(); - - // Register the socket - state.lock().unwrap() - .peers.insert(addr, tx); - - // Split the `lines` handle into send and recv handles. This allows spawning - // separate tasks. - let (mut lines_tx, mut lines_rx) = lines.split(); - - // Spawn a task that receives all lines broadcasted to us from other peers - // and writes it to the client. - tokio::spawn_async(async move { - while let Some(line) = await!(rx.next()) { - let line = line.unwrap(); - await!(lines_tx.send_async(line)).unwrap(); - } - }); - - // Use the current task to read lines from the socket and broadcast them to - // other peers. - while let Some(message) = await!(lines_rx.next()) { - // TODO: Error handling - let message = message.unwrap(); - - let mut line = name.clone(); - line.push_str(": "); - line.push_str(&message); - line.push_str("\r\n"); - - let state = state.lock().unwrap(); - - for (peer_addr, tx) in &state.peers { - if *peer_addr != addr { - // TODO: Error handling - tx.unbounded_send(line.clone()).unwrap(); - } - } - } - - // Remove the client from the shared state. Doing so will also result in the - // tx task to terminate. - state.lock().unwrap() - .peers.remove(&addr) - .expect("bug"); - - Ok(()) -} - -#[tokio::main] -async fn main() { - // Create the shared state. This is how all the peers communicate. - // - // The server task will hold a handle to this. For every new client, the - // `state` handle is cloned and passed into the task that processes the - // client connection. - let state = Arc::new(Mutex::new(Shared::new())); - - let addr = "127.0.0.1:6142".parse().unwrap(); - - // Bind a TCP listener to the socket address. - // - // Note that this is the Tokio TcpListener, which is fully async. - let listener = TcpListener::bind(&addr).unwrap(); - - println!("server running on localhost:6142"); - - // Start the Tokio runtime. - let mut incoming = listener.incoming(); - - while let Some(stream) = await!(incoming.next()) { - let stream = match stream { - Ok(stream) => stream, - Err(_) => continue, - }; - - let state = state.clone(); - - tokio::spawn_async(async move { - if let Err(_) = await!(process(stream, state)) { - eprintln!("failed to process connection"); - } - }); - } -} - diff --git a/async-await/src/echo_client.rs b/async-await/src/echo_client.rs deleted file mode 100644 index 7cab4932e..000000000 --- a/async-await/src/echo_client.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![feature(await_macro, async_await)] - -use tokio::await; -use tokio::net::TcpStream; -use tokio::prelude::*; - -use std::io; -use std::net::SocketAddr; - -const MESSAGES: &[&str] = &[ - "hello", - "world", - "one two three", -]; - -async fn run_client(addr: &SocketAddr) -> io::Result<()> { - let mut stream = await!(TcpStream::connect(addr))?; - - // Buffer to read into - let mut buf = [0; 128]; - - for msg in MESSAGES { - println!(" > write = {:?}", msg); - - // Write the message to the server - await!(stream.write_all_async(msg.as_bytes()))?; - - // Read the message back from the server - await!(stream.read_exact_async(&mut buf[..msg.len()]))?; - - assert_eq!(&buf[..msg.len()], msg.as_bytes()); - } - - Ok(()) -} - -#[tokio::main] -async fn main() { - use std::env; - - let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string()); - let addr = addr.parse::().unwrap(); - - // Connect to the echo serveer - - match await!(run_client(&addr)) { - Ok(_) => println!("done."), - Err(e) => eprintln!("echo client failed; error = {:?}", e), - } -} diff --git a/async-await/src/echo_server.rs b/async-await/src/echo_server.rs deleted file mode 100644 index d282ad6bc..000000000 --- a/async-await/src/echo_server.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![feature(await_macro, async_await)] - -use tokio::await; -use tokio::net::{TcpListener, TcpStream}; -use tokio::prelude::*; - -use std::net::SocketAddr; - -fn handle(mut stream: TcpStream) { - tokio::spawn_async(async move { - let mut buf = [0; 1024]; - - loop { - match await!(stream.read_async(&mut buf)).unwrap() { - 0 => break, // Socket closed - n => { - // Send the data back - await!(stream.write_all_async(&buf[0..n])).unwrap(); - } - } - } - }); -} - -#[tokio::main] -async fn main() { - use std::env; - - let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string()); - let addr = addr.parse::().unwrap(); - - // Bind the TCP listener - let listener = TcpListener::bind(&addr).unwrap(); - println!("Listening on: {}", addr); - - let mut incoming = listener.incoming(); - - while let Some(stream) = await!(incoming.next()) { - let stream = stream.unwrap(); - handle(stream); - } -} diff --git a/async-await/src/hyper.rs b/async-await/src/hyper.rs deleted file mode 100644 index c86481b43..000000000 --- a/async-await/src/hyper.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![feature(await_macro, async_await)] - -use tokio::await; -use tokio::prelude::*; -use hyper::Client; - -use std::time::Duration; -use std::str; - -#[tokio::main] -async fn main() { - let client = Client::new(); - - let uri = "http://httpbin.org/ip".parse().unwrap(); - - let response = await!({ - client.get(uri) - .timeout(Duration::from_secs(10)) - }).unwrap(); - - println!("Response: {}", response.status()); - - let mut body = response.into_body(); - - while let Some(chunk) = await!(body.next()) { - let chunk = chunk.unwrap(); - println!("chunk = {}", str::from_utf8(&chunk[..]).unwrap()); - } -} diff --git a/async-await/tests/macros.rs b/async-await/tests/macros.rs deleted file mode 100644 index 285e5538a..000000000 --- a/async-await/tests/macros.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![feature(await_macro, async_await)] - -use tokio::await; -use tokio::timer::Delay; -use std::time::{Duration, Instant}; - -#[tokio::test] -async fn success_no_async() { - assert!(true); -} - -#[tokio::test] -#[should_panic] -async fn fail_no_async() { - assert!(false); -} - -#[tokio::test] -async fn use_timer() { - let when = Instant::now() + Duration::from_millis(10); - await!(Delay::new(when)); -} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f345ff800..770b96ddc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -68,13 +68,6 @@ jobs: tokio-buf: - util -# Run async-await tests -- template: ci/azure-test-nightly.yml - parameters: - name: test_nightly - displayName: Test Async / Await - rust: nightly-2019-04-25 - # Try cross compiling - template: ci/azure-cross-compile.yml parameters: @@ -105,7 +98,6 @@ jobs: - test_sub_cross - test_linux - features - - test_nightly - cross_32bit_linux - minrust - tsan diff --git a/ci/azure-test-nightly.yml b/ci/azure-test-nightly.yml deleted file mode 100644 index bbb444426..000000000 --- a/ci/azure-test-nightly.yml +++ /dev/null @@ -1,19 +0,0 @@ -jobs: -- job: ${{ parameters.name }} - displayName: ${{ parameters.displayName }} - pool: - vmImage: ubuntu-16.04 - - steps: - - template: azure-install-rust.yml - parameters: - rust_version: ${{ parameters.rust }} - - - template: azure-patch-crates.yml - - - script: cargo check --all - displayName: cargo check --all - - # Check benches - - script: cargo check --benches --all - displayName: Check benchmarks