From 20871ae69dfb60f629148742d19ae7b6fd87e849 Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Fri, 14 Apr 2023 15:49:38 -0400 Subject: [PATCH] Upgrade deadpool dependency. --- Cargo.toml | 4 ++-- src/h1/mod.rs | 25 ++++++++++++------------- src/h1/tcp.rs | 9 ++++++--- src/h1/tls.rs | 9 ++++++--- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4c47488..ab4aad5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ unstable-config = [] # deprecated [dependencies] async-trait = "0.1.37" -http-types = "2.3.0" +http-types = "2.12.0" log = "0.4.7" cfg-if = "1.0.0" @@ -45,7 +45,7 @@ async-h1 = { version = "2.0.0", optional = true } async-std = { version = "1.6.0", default-features = false, optional = true } async-native-tls = { version = "0.3.1", optional = true } dashmap = { version = "5.3.4", optional = true } -deadpool = { version = "0.7.0", optional = true } +deadpool = { version = "0.9.5", optional = true } futures = { version = "0.3.8", optional = true } # h1_client_rustls diff --git a/src/h1/mod.rs b/src/h1/mod.rs index e44e765..5dfc555 100644 --- a/src/h1/mod.rs +++ b/src/h1/mod.rs @@ -6,7 +6,6 @@ use std::net::SocketAddr; use std::sync::Arc; use async_h1::client; -use async_std::net::TcpStream; use dashmap::DashMap; use deadpool::managed::Pool; use http_types::StatusCode; @@ -14,8 +13,6 @@ use http_types::StatusCode; cfg_if::cfg_if! { if #[cfg(feature = "rustls")] { use async_tls::client::TlsStream; - } else if #[cfg(feature = "native-tls")] { - use async_native_tls::TlsStream; } } @@ -31,9 +28,9 @@ use tcp::{TcpConnWrapper, TcpConnection}; #[cfg(any(feature = "native-tls", feature = "rustls"))] use tls::{TlsConnWrapper, TlsConnection}; -type HttpPool = DashMap>; +type HttpPool = DashMap>; #[cfg(any(feature = "native-tls", feature = "rustls"))] -type HttpsPool = DashMap, Error>>; +type HttpsPool = DashMap>; /// async-h1 based HTTP Client, with connection pooling ("Keep-Alive"). pub struct H1Client { @@ -193,10 +190,9 @@ impl HttpClient for H1Client { pool_ref } else { let manager = TcpConnection::new(addr, self.config.clone()); - let pool = Pool::::new( - manager, - self.config.max_connections_per_host, - ); + let pool = Pool::builder(manager) + .max_size(self.config.max_connections_per_host) + .build()?; self.http_pools.insert(addr, pool); self.http_pools.get(&addr).unwrap() }; @@ -227,10 +223,13 @@ impl HttpClient for H1Client { pool_ref } else { let manager = TlsConnection::new(host.clone(), addr, self.config.clone()); - let pool = Pool::, Error>::new( - manager, - self.config.max_connections_per_host, - ); + let pool = Pool::builder(manager) + .max_size(self.config.max_connections_per_host) + .build() + .map_err(|error| { + // TODO implement Error for http_types::Error + std::io::Error::new(std::io::ErrorKind::Other, format!("{}", error)) + })?; self.https_pools.insert(addr, pool); self.https_pools.get(&addr).unwrap() }; diff --git a/src/h1/tcp.rs b/src/h1/tcp.rs index 2887bc0..dc5db8f 100644 --- a/src/h1/tcp.rs +++ b/src/h1/tcp.rs @@ -24,10 +24,10 @@ impl TcpConnection { } pub(crate) struct TcpConnWrapper { - conn: Object, + conn: Object, } impl TcpConnWrapper { - pub(crate) fn new(conn: Object) -> Self { + pub(crate) fn new(conn: Object) -> Self { Self { conn } } } @@ -61,7 +61,10 @@ impl AsyncWrite for TcpConnWrapper { } #[async_trait] -impl Manager for TcpConnection { +impl Manager for TcpConnection { + type Type = TcpStream; + type Error = std::io::Error; + async fn create(&self) -> Result { let tcp_stream = TcpStream::connect(self.addr).await?; diff --git a/src/h1/tls.rs b/src/h1/tls.rs index 7d3ecf4..e6e6d64 100644 --- a/src/h1/tls.rs +++ b/src/h1/tls.rs @@ -33,10 +33,10 @@ impl TlsConnection { } pub(crate) struct TlsConnWrapper { - conn: Object, Error>, + conn: Object, } impl TlsConnWrapper { - pub(crate) fn new(conn: Object, Error>) -> Self { + pub(crate) fn new(conn: Object) -> Self { Self { conn } } } @@ -70,7 +70,10 @@ impl AsyncWrite for TlsConnWrapper { } #[async_trait] -impl Manager, Error> for TlsConnection { +impl Manager for TlsConnection { + type Type = TlsStream; + type Error = Error; + async fn create(&self) -> Result, Error> { let raw_stream = async_std::net::TcpStream::connect(self.addr).await?;