From 7a73c22814c6a8ca5d53e7669abcd69ce2794de7 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 20 Jul 2020 00:55:35 +0200 Subject: [PATCH 1/4] Reduce the number of dependencies --- Cargo.toml | 3 ++- examples/async-h1-client.rs | 2 +- examples/async-h1-server.rs | 2 +- examples/chat-client.rs | 20 ++++++++++++++------ examples/chat-server.rs | 5 ++--- examples/ctrl-c.rs | 4 ++-- examples/hyper-client.rs | 6 +++--- examples/hyper-server.rs | 10 +++++----- examples/simple-client.rs | 2 +- examples/simple-server.rs | 2 +- examples/tcp-client.rs | 3 +-- examples/tcp-server.rs | 2 +- examples/tls-client.rs | 3 +-- examples/tls-server.rs | 2 +- examples/unix-signal.rs | 2 +- examples/websocket-client.rs | 3 ++- examples/websocket-server.rs | 3 ++- examples/windows-uds.rs | 3 +-- 18 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 350b8c9..0e05744 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,8 @@ async-std = "1.5.0" async-tungstenite = { version = "0.4.2", features = ["async-native-tls"] } base64 = "0.12.0" ctrlc = "3.1.4" -futures = "0.3.4" +futures = "0.3.5" +futures-lite = { path = "../futures-lite" } http = "0.2.1" http-types = "1.2.0" hyper = { version = "0.13.5", default-features = false, features = ["stream"] } diff --git a/examples/async-h1-client.rs b/examples/async-h1-client.rs index 645b0e3..2b1f5bd 100644 --- a/examples/async-h1-client.rs +++ b/examples/async-h1-client.rs @@ -11,7 +11,7 @@ use std::net::{TcpStream, ToSocketAddrs}; use anyhow::{bail, Context as _, Error, Result}; use async_io::Async; use blocking::{block_on, unblock}; -use futures::prelude::*; +use futures_lite::*; use http_types::{Method, Request, Response}; use url::Url; diff --git a/examples/async-h1-server.rs b/examples/async-h1-server.rs index dfd468d..ec34a65 100644 --- a/examples/async-h1-server.rs +++ b/examples/async-h1-server.rs @@ -19,7 +19,7 @@ use anyhow::Result; use async_io::Async; use async_native_tls::{Identity, TlsAcceptor}; use blocking::block_on; -use futures::prelude::*; +use futures_lite::*; use http_types::{Request, Response, StatusCode}; use smol::Task; diff --git a/examples/chat-client.rs b/examples/chat-client.rs index e69597c..1085863 100644 --- a/examples/chat-client.rs +++ b/examples/chat-client.rs @@ -16,8 +16,7 @@ use std::net::TcpStream; use async_io::Async; use blocking::{block_on, Unblock}; -use futures::io; -use futures::prelude::*; +use futures_lite::*; fn main() -> io::Result<()> { block_on(async { @@ -35,10 +34,19 @@ fn main() -> io::Result<()> { let mut writer = &stream; // Wait until the standard input is closed or the connection is closed. - futures::select! { - _ = io::copy(stdin, &mut writer).fuse() => println!("Quit!"), - _ = io::copy(reader, &mut stdout).fuse() => println!("Server disconnected!"), - } + future::race( + async { + let res = io::copy(stdin, &mut writer).await; + println!("Quit!"); + res + }, + async { + let res = io::copy(reader, &mut stdout).await; + println!("Server disconnected!"); + res + }, + ) + .await?; Ok(()) }) diff --git a/examples/chat-server.rs b/examples/chat-server.rs index 7ea38fe..1d78c86 100644 --- a/examples/chat-server.rs +++ b/examples/chat-server.rs @@ -19,8 +19,7 @@ use async_channel::{bounded, Receiver, Sender}; use async_dup::Arc; use async_io::Async; use blocking::block_on; -use futures::io::{self, BufReader}; -use futures::prelude::*; +use futures_lite::*; use smol::Task; /// An event on the chat server. @@ -70,7 +69,7 @@ async fn dispatch(receiver: Receiver) -> io::Result<()> { /// Reads messages from the client and forwards them to the dispatcher task. async fn read_messages(sender: Sender, client: Arc>) -> io::Result<()> { let addr = client.get_ref().peer_addr()?; - let mut lines = BufReader::new(client).lines(); + let mut lines = io::BufReader::new(client).lines(); while let Some(line) = lines.next().await { let line = line?; diff --git a/examples/ctrl-c.rs b/examples/ctrl-c.rs index bf7e57e..a71daef 100644 --- a/examples/ctrl-c.rs +++ b/examples/ctrl-c.rs @@ -7,13 +7,13 @@ //! ``` use blocking::block_on; -use futures::prelude::*; +use futures_lite::*; fn main() { // Set a handler that sends a message through a channel. let (s, ctrl_c) = async_channel::bounded(100); let handle = move || { - let _ = s.send(()).now_or_never(); + let _ = future::poll_once(s.send(())); }; ctrlc::set_handler(handle).unwrap(); diff --git a/examples/hyper-client.rs b/examples/hyper-client.rs index f3ba818..5d3487c 100644 --- a/examples/hyper-client.rs +++ b/examples/hyper-client.rs @@ -16,7 +16,7 @@ use anyhow::{bail, Context as _, Error, Result}; use async_io::Async; use async_native_tls::TlsStream; use blocking::{block_on, unblock}; -use futures::prelude::*; +use futures_lite::*; use http::Uri; use hyper::{Body, Client, Request, Response}; use smol::Task; @@ -42,7 +42,7 @@ fn main() -> Result<()> { // Read the message body. let body = resp .into_body() - .try_fold(Vec::new(), |mut body, chunk| async move { + .try_fold(Vec::new(), |mut body, chunk| { body.extend_from_slice(&chunk); Ok(body) }) @@ -70,7 +70,7 @@ struct SmolConnector; impl hyper::service::Service for SmolConnector { type Response = SmolStream; type Error = Error; - type Future = future::BoxFuture<'static, Result>; + type Future = Pin> + Send>>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) diff --git a/examples/hyper-server.rs b/examples/hyper-server.rs index 0073894..381a2a9 100644 --- a/examples/hyper-server.rs +++ b/examples/hyper-server.rs @@ -23,7 +23,7 @@ use anyhow::{Error, Result}; use async_io::Async; use async_native_tls::{Identity, TlsAcceptor, TlsStream}; use blocking::block_on; -use futures::prelude::*; +use futures_lite::*; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Request, Response, Server}; use smol::Task; @@ -103,7 +103,7 @@ impl hyper::server::accept::Accept for SmolListener { cx: &mut Context, ) -> Poll>> { let poll = Pin::new(&mut self.listener.incoming()).poll_next(cx); - let stream = futures::ready!(poll).unwrap()?; + let stream = ready!(poll).unwrap()?; let stream = match &self.tls { None => SmolStream::Plain(stream), @@ -132,7 +132,7 @@ enum SmolStream { Tls(TlsStream>), /// A TCP connection that is in process of getting secured by TLS. - Handshake(future::BoxFuture<'static, io::Result>>>), + Handshake(Pin>>> + Send>>), } impl hyper::client::connect::Connection for SmolStream { @@ -152,7 +152,7 @@ impl tokio::io::AsyncRead for SmolStream { SmolStream::Plain(s) => return Pin::new(s).poll_read(cx, buf), SmolStream::Tls(s) => return Pin::new(s).poll_read(cx, buf), SmolStream::Handshake(f) => { - let s = futures::ready!(f.as_mut().poll(cx))?; + let s = ready!(f.as_mut().poll(cx))?; *self = SmolStream::Tls(s); } } @@ -171,7 +171,7 @@ impl tokio::io::AsyncWrite for SmolStream { SmolStream::Plain(s) => return Pin::new(s).poll_write(cx, buf), SmolStream::Tls(s) => return Pin::new(s).poll_write(cx, buf), SmolStream::Handshake(f) => { - let s = futures::ready!(f.as_mut().poll(cx))?; + let s = ready!(f.as_mut().poll(cx))?; *self = SmolStream::Tls(s); } } diff --git a/examples/simple-client.rs b/examples/simple-client.rs index e0b9acf..534fb35 100644 --- a/examples/simple-client.rs +++ b/examples/simple-client.rs @@ -11,7 +11,7 @@ use std::net::{TcpStream, ToSocketAddrs}; use anyhow::{bail, Context as _, Result}; use async_io::Async; use blocking::{block_on, unblock}; -use futures::prelude::*; +use futures_lite::*; use url::Url; /// Sends a GET request and fetches the response. diff --git a/examples/simple-server.rs b/examples/simple-server.rs index 48c6302..3dfcaf5 100644 --- a/examples/simple-server.rs +++ b/examples/simple-server.rs @@ -19,7 +19,7 @@ use anyhow::Result; use async_io::Async; use async_native_tls::{Identity, TlsAcceptor}; use blocking::block_on; -use futures::prelude::*; +use futures_lite::*; use smol::Task; const RESPONSE: &[u8] = br#" diff --git a/examples/tcp-client.rs b/examples/tcp-client.rs index d0d82c5..aadafde 100644 --- a/examples/tcp-client.rs +++ b/examples/tcp-client.rs @@ -16,8 +16,7 @@ use std::net::TcpStream; use async_io::Async; use blocking::{block_on, Unblock}; -use futures::io; -use futures::prelude::*; +use futures_lite::*; fn main() -> io::Result<()> { block_on(async { diff --git a/examples/tcp-server.rs b/examples/tcp-server.rs index 98a0926..e61063e 100644 --- a/examples/tcp-server.rs +++ b/examples/tcp-server.rs @@ -16,7 +16,7 @@ use std::net::{TcpListener, TcpStream}; use async_io::Async; use blocking::block_on; -use futures::io; +use futures_lite::*; use smol::Task; /// Echoes messages from the client back to it. diff --git a/examples/tls-client.rs b/examples/tls-client.rs index e635bf7..bc57de2 100644 --- a/examples/tls-client.rs +++ b/examples/tls-client.rs @@ -18,8 +18,7 @@ use anyhow::Result; use async_io::Async; use async_native_tls::{Certificate, TlsConnector}; use blocking::{block_on, Unblock}; -use futures::io; -use futures::prelude::*; +use futures_lite::*; fn main() -> Result<()> { // Initialize TLS with the local certificate. diff --git a/examples/tls-server.rs b/examples/tls-server.rs index a08acec..a7ff32b 100644 --- a/examples/tls-server.rs +++ b/examples/tls-server.rs @@ -18,7 +18,7 @@ use anyhow::Result; use async_io::Async; use async_native_tls::{Identity, TlsAcceptor, TlsStream}; use blocking::block_on; -use futures::io; +use futures_lite::*; use smol::Task; /// Echoes messages from the client back to it. diff --git a/examples/unix-signal.rs b/examples/unix-signal.rs index 45ae5c0..5d4d681 100644 --- a/examples/unix-signal.rs +++ b/examples/unix-signal.rs @@ -12,7 +12,7 @@ fn main() -> std::io::Result<()> { use async_io::Async; use blocking::block_on; - use futures::prelude::*; + use futures_lite::*; block_on(async { // Create a Unix stream that receives a byte on each signal occurrence. diff --git a/examples/websocket-client.rs b/examples/websocket-client.rs index 9375a57..4d32c5d 100644 --- a/examples/websocket-client.rs +++ b/examples/websocket-client.rs @@ -21,7 +21,8 @@ use async_io::Async; use async_native_tls::{Certificate, TlsConnector, TlsStream}; use async_tungstenite::WebSocketStream; use blocking::{block_on, unblock}; -use futures::prelude::*; +use futures::sink::{Sink, SinkExt}; +use futures_lite::*; use tungstenite::handshake::client::Response; use tungstenite::Message; use url::Url; diff --git a/examples/websocket-server.rs b/examples/websocket-server.rs index f756458..93a942e 100644 --- a/examples/websocket-server.rs +++ b/examples/websocket-server.rs @@ -21,7 +21,8 @@ use async_io::Async; use async_native_tls::{Identity, TlsAcceptor, TlsStream}; use async_tungstenite::WebSocketStream; use blocking::block_on; -use futures::prelude::*; +use futures::sink::{Sink, SinkExt}; +use futures_lite::*; use smol::Task; use tungstenite::Message; diff --git a/examples/windows-uds.rs b/examples/windows-uds.rs index 2f1a34b..a1e3138 100644 --- a/examples/windows-uds.rs +++ b/examples/windows-uds.rs @@ -12,8 +12,7 @@ fn main() -> std::io::Result<()> { use async_io::Async; use blocking::{block_on, Unblock}; - use futures::io; - use futures::prelude::*; + use futures_lite::*; use smol::Task; use tempfile::tempdir; use uds_windows::{UnixListener, UnixStream}; From 07ea6cc9f78a840cce50069bbf415e6542f1572c Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 20 Jul 2020 00:56:40 +0200 Subject: [PATCH 2/4] Update futures-lite --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0e05744..3a4a4c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ async-tungstenite = { version = "0.4.2", features = ["async-native-tls"] } base64 = "0.12.0" ctrlc = "3.1.4" futures = "0.3.5" -futures-lite = { path = "../futures-lite" } +futures-lite = "0.1.5" http = "0.2.1" http-types = "1.2.0" hyper = { version = "0.13.5", default-features = false, features = ["stream"] } From 8a1efd58ea8e558b115446aa7990e2197b355781 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 20 Jul 2020 00:57:31 +0200 Subject: [PATCH 3/4] Update all dependencies --- Cargo.toml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a4a4c5..7205466 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,48 +24,48 @@ readme = "README.md" tokio02 = ["tokio"] [dependencies] -async-io = "0.1.1" +async-io = "0.1.3" multitask = "0.2.0" num_cpus = "1.13.0" once_cell = "1.4.0" -blocking = "0.4.6" +blocking = "0.4.7" [dependencies.tokio] -version = "0.2" +version = "0.2.21" default-features = false features = ["rt-threaded"] optional = true [dev-dependencies] -anyhow = "1.0.28" +anyhow = "1.0.31" async-channel = "1.1.1" -async-dup = "1.1.0" -async-h1 = "1.1.2" +async-dup = "1.2.1" +async-h1 = "2.1.0" async-native-tls = "0.3.3" -async-std = "1.5.0" -async-tungstenite = { version = "0.4.2", features = ["async-native-tls"] } -base64 = "0.12.0" -ctrlc = "3.1.4" +async-std = "1.6.2" +async-tungstenite = { version = "0.7.1", features = ["async-native-tls"] } +base64 = "0.12.3" +ctrlc = "3.1.5" futures = "0.3.5" futures-lite = "0.1.5" http = "0.2.1" -http-types = "1.2.0" -hyper = { version = "0.13.5", default-features = false, features = ["stream"] } +http-types = "2.3.0" +hyper = { version = "0.13.7", default-features = false, features = ["stream"] } native-tls = "0.2.4" num_cpus = "1.13.0" -reqwest = "0.10.4" -scraper = "0.11.0" -signal-hook = "0.1.13" -surf = { version = "2.0.0-alpha.1", default-features = false, features = ["h1-client"] } +reqwest = "0.10.6" +scraper = "0.12.0" +signal-hook = "0.1.16" +surf = { version = "2.0.0-alpha.4", default-features = false, features = ["h1-client"] } tempfile = "3.1.0" -tokio = { version = "0.2", default-features = false } -tungstenite = "0.10.1" +tokio = { version = "0.2.21", default-features = false } +tungstenite = "0.11.0" url = "2.1.1" [target.'cfg(target_os = "linux")'.dev-dependencies] -inotify = { version = "0.8.2", default-features = false } +inotify = { version = "0.8.3", default-features = false } nix = "0.17.0" timerfd = "1.1.1" [target.'cfg(windows)'.dev-dependencies] -uds_windows = "0.1.4" +uds_windows = "0.1.5" From a2c24e960437886db5eb7a31c6daddd24c7d3606 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 20 Jul 2020 08:45:56 +0200 Subject: [PATCH 4/4] Fix compilation errors with async-h1 --- examples/async-h1-server.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/async-h1-server.rs b/examples/async-h1-server.rs index ec34a65..69014df 100644 --- a/examples/async-h1-server.rs +++ b/examples/async-h1-server.rs @@ -28,7 +28,7 @@ async fn serve(req: Request) -> http_types::Result { println!("Serving {}", req.url()); let mut res = Response::new(StatusCode::Ok); - res.insert_header("Content-Type", "text/plain")?; + res.insert_header("Content-Type", "text/plain"); res.set_body("Hello from async-h1!"); Ok(res) } @@ -45,14 +45,13 @@ async fn listen(listener: Async, tls: Option) -> Resul loop { // Accept the next connection. let (stream, _) = listener.accept().await?; - let host = host.clone(); // Spawn a background task serving this connection. let task = match &tls { None => { let stream = async_dup::Arc::new(stream); Task::spawn(async move { - if let Err(err) = async_h1::accept(&host, stream, serve).await { + if let Err(err) = async_h1::accept(stream, serve).await { println!("Connection error: {:#?}", err); } }) @@ -63,7 +62,7 @@ async fn listen(listener: Async, tls: Option) -> Resul Ok(stream) => { let stream = async_dup::Arc::new(async_dup::Mutex::new(stream)); Task::spawn(async move { - if let Err(err) = async_h1::accept(&host, stream, serve).await { + if let Err(err) = async_h1::accept(stream, serve).await { println!("Connection error: {:#?}", err); } })