From 2645a2aa88551deddea736242f253f013fe1faee Mon Sep 17 00:00:00 2001 From: Urhengulas Date: Tue, 20 Oct 2020 19:08:13 +0200 Subject: [PATCH 1/5] Bump tokio from 0.2 to 0.3 * `Cargo.toml` * bump `tokio` from `0.2` to `0.3` * exchange `tokio-tls` with `tokio-native-tls 0.2` * `stream`: * adapt `impl AsyncRead for MaybeHttpsStream` * adapt `impl AsyncWrite for MaybeHttpsStream` * adapt `impl Connection for MaybeHttpsStream` --- Cargo.toml | 6 +++--- src/client.rs | 2 +- src/stream.rs | 45 ++++++--------------------------------------- 3 files changed, 10 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 94b54d9..785df16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ vendored = ["native-tls/vendored"] bytes = "0.5" native-tls = "0.2" hyper = { version = "0.13", default-features = false, features = ["tcp"] } -tokio = { version = "0.2" } -tokio-tls = "0.3" +tokio = { version = "0.3" } +tokio-native-tls = "0.2" [dev-dependencies] -tokio = { version = "0.2", features = ["io-std", "macros"] } +tokio = { version = "0.3", features = ["full"] } diff --git a/src/client.rs b/src/client.rs index a0cf624..1f4f8c2 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,7 +5,7 @@ use std::task::{Context, Poll}; use hyper::{client::connect::HttpConnector, service::Service, Uri}; use tokio::io::{AsyncRead, AsyncWrite}; -use tokio_tls::TlsConnector; +use tokio_native_tls::TlsConnector; use crate::stream::MaybeHttpsStream; diff --git a/src/stream.rs b/src/stream.rs index a924c2c..6ff39c5 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -3,10 +3,9 @@ use std::io; use std::pin::Pin; use std::task::{Context, Poll}; -use bytes::{Buf, BufMut}; use hyper::client::connect::{Connected, Connection}; -use tokio::io::{AsyncRead, AsyncWrite}; -pub use tokio_tls::TlsStream; +use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; +pub use tokio_native_tls::TlsStream; /// A stream that might be protected with TLS. pub enum MaybeHttpsStream { @@ -40,37 +39,17 @@ impl From> for MaybeHttpsStream { } impl AsyncRead for MaybeHttpsStream { - #[inline] - unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit]) -> bool { - match self { - MaybeHttpsStream::Http(s) => s.prepare_uninitialized_buffer(buf), - MaybeHttpsStream::Https(s) => s.prepare_uninitialized_buffer(buf), - } - } - #[inline] fn poll_read( self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut [u8], - ) -> Poll> { + cx: &mut Context<'_>, + buf: &mut ReadBuf<'_>, + ) -> Poll> { match Pin::get_mut(self) { MaybeHttpsStream::Http(s) => Pin::new(s).poll_read(cx, buf), MaybeHttpsStream::Https(s) => Pin::new(s).poll_read(cx, buf), } } - - #[inline] - fn poll_read_buf( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut B, - ) -> Poll> { - match Pin::get_mut(self) { - MaybeHttpsStream::Http(s) => Pin::new(s).poll_read_buf(cx, buf), - MaybeHttpsStream::Https(s) => Pin::new(s).poll_read_buf(cx, buf), - } - } } impl AsyncWrite for MaybeHttpsStream { @@ -86,18 +65,6 @@ impl AsyncWrite for MaybeHttpsStream { } } - #[inline] - fn poll_write_buf( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut B, - ) -> Poll> { - match Pin::get_mut(self) { - MaybeHttpsStream::Http(s) => Pin::new(s).poll_write_buf(cx, buf), - MaybeHttpsStream::Https(s) => Pin::new(s).poll_write_buf(cx, buf), - } - } - #[inline] fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match Pin::get_mut(self) { @@ -119,7 +86,7 @@ impl Connection for MaybeHttpsSt fn connected(&self) -> Connected { match self { MaybeHttpsStream::Http(s) => s.connected(), - MaybeHttpsStream::Https(s) => s.get_ref().connected(), + MaybeHttpsStream::Https(s) => s.get_ref().get_ref().get_ref().connected(), } } } From 9a55a82c18a34e4681c6a571b9431ab58f062ba5 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 6 Nov 2020 14:42:03 +0800 Subject: [PATCH 2/5] Use hyper 0.14-dev --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 785df16..901bf9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ vendored = ["native-tls/vendored"] [dependencies] bytes = "0.5" native-tls = "0.2" -hyper = { version = "0.13", default-features = false, features = ["tcp"] } +hyper = { git = "https://github.com/hyperium/hyper.git", default-features = false, features = ["tcp"] } tokio = { version = "0.3" } tokio-native-tls = "0.2" From f326fbd3000d14a20d3af4d4627837cceabeaadb Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 19 Nov 2020 14:08:17 +0800 Subject: [PATCH 3/5] Re-enable vectored write --- Cargo.toml | 4 ++-- src/stream.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 901bf9d..f6eb4e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ vendored = ["native-tls/vendored"] [dependencies] bytes = "0.5" native-tls = "0.2" -hyper = { git = "https://github.com/hyperium/hyper.git", default-features = false, features = ["tcp"] } -tokio = { version = "0.3" } +hyper = { git = "https://github.com/hyperium/hyper.git", default-features = false, features = ["tcp", "client", "http1"] } +tokio = { version = "0.3.4" } tokio-native-tls = "0.2" [dev-dependencies] diff --git a/src/stream.rs b/src/stream.rs index 6ff39c5..25f225f 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -65,6 +65,26 @@ impl AsyncWrite for MaybeHttpsStream { } } + #[inline] + fn poll_write_vectored( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + bufs: &[io::IoSlice<'_>], + ) -> Poll> { + match Pin::get_mut(self) { + MaybeHttpsStream::Http(s) => Pin::new(s).poll_write_vectored(cx, bufs), + MaybeHttpsStream::Https(s) => Pin::new(s).poll_write_vectored(cx, bufs), + } + } + + #[inline] + fn is_write_vectored(&self) -> bool { + match self { + MaybeHttpsStream::Http(s) => s.is_write_vectored(), + MaybeHttpsStream::Https(s) => s.is_write_vectored(), + } + } + #[inline] fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match Pin::get_mut(self) { From 07dc2306696b83d1a16476ea04c8c0755e6bff9d Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 22 Nov 2020 14:02:31 +0800 Subject: [PATCH 4/5] Update bytes to 0.6 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f6eb4e2..4878193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" vendored = ["native-tls/vendored"] [dependencies] -bytes = "0.5" +bytes = "0.6" native-tls = "0.2" hyper = { git = "https://github.com/hyperium/hyper.git", default-features = false, features = ["tcp", "client", "http1"] } tokio = { version = "0.3.4" } From 8e9ce226bc57a5c5f42017b608006891bad48a96 Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 24 Dec 2020 11:23:56 +0800 Subject: [PATCH 5/5] Update to tokio 1.0 --- Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4878193..c1ba1fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,11 +14,11 @@ edition = "2018" vendored = ["native-tls/vendored"] [dependencies] -bytes = "0.6" +bytes = "1.0" native-tls = "0.2" -hyper = { git = "https://github.com/hyperium/hyper.git", default-features = false, features = ["tcp", "client", "http1"] } -tokio = { version = "0.3.4" } -tokio-native-tls = "0.2" +hyper = { version = "0.14", default-features = false, features = ["tcp", "client", "http1"] } +tokio = { version = "1.0" } +tokio-native-tls = { git = "https://github.com/tokio-rs/tls.git" } [dev-dependencies] -tokio = { version = "0.3", features = ["full"] } +tokio = { version = "1.0", features = ["full"] }