Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade deadpool dependency #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
25 changes: 12 additions & 13 deletions src/h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ 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;

cfg_if::cfg_if! {
if #[cfg(feature = "rustls")] {
use async_tls::client::TlsStream;
} else if #[cfg(feature = "native-tls")] {
use async_native_tls::TlsStream;
}
}

Expand All @@ -31,9 +28,9 @@ use tcp::{TcpConnWrapper, TcpConnection};
#[cfg(any(feature = "native-tls", feature = "rustls"))]
use tls::{TlsConnWrapper, TlsConnection};

type HttpPool = DashMap<SocketAddr, Pool<TcpStream, std::io::Error>>;
type HttpPool = DashMap<SocketAddr, Pool<TcpConnection>>;
#[cfg(any(feature = "native-tls", feature = "rustls"))]
type HttpsPool = DashMap<SocketAddr, Pool<TlsStream<TcpStream>, Error>>;
type HttpsPool = DashMap<SocketAddr, Pool<TlsConnection>>;

/// async-h1 based HTTP Client, with connection pooling ("Keep-Alive").
pub struct H1Client {
Expand Down Expand Up @@ -193,10 +190,9 @@ impl HttpClient for H1Client {
pool_ref
} else {
let manager = TcpConnection::new(addr, self.config.clone());
let pool = Pool::<TcpStream, std::io::Error>::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()
};
Expand Down Expand Up @@ -227,10 +223,13 @@ impl HttpClient for H1Client {
pool_ref
} else {
let manager = TlsConnection::new(host.clone(), addr, self.config.clone());
let pool = Pool::<TlsStream<TcpStream>, 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()
};
Expand Down
9 changes: 6 additions & 3 deletions src/h1/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ impl TcpConnection {
}

pub(crate) struct TcpConnWrapper {
conn: Object<TcpStream, std::io::Error>,
conn: Object<TcpConnection>,
}
impl TcpConnWrapper {
pub(crate) fn new(conn: Object<TcpStream, std::io::Error>) -> Self {
pub(crate) fn new(conn: Object<TcpConnection>) -> Self {
Self { conn }
}
}
Expand Down Expand Up @@ -61,7 +61,10 @@ impl AsyncWrite for TcpConnWrapper {
}

#[async_trait]
impl Manager<TcpStream, std::io::Error> for TcpConnection {
impl Manager for TcpConnection {
type Type = TcpStream;
type Error = std::io::Error;

async fn create(&self) -> Result<TcpStream, std::io::Error> {
let tcp_stream = TcpStream::connect(self.addr).await?;

Expand Down
9 changes: 6 additions & 3 deletions src/h1/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ impl TlsConnection {
}

pub(crate) struct TlsConnWrapper {
conn: Object<TlsStream<TcpStream>, Error>,
conn: Object<TlsConnection>,
}
impl TlsConnWrapper {
pub(crate) fn new(conn: Object<TlsStream<TcpStream>, Error>) -> Self {
pub(crate) fn new(conn: Object<TlsConnection>) -> Self {
Self { conn }
}
}
Expand Down Expand Up @@ -70,7 +70,10 @@ impl AsyncWrite for TlsConnWrapper {
}

#[async_trait]
impl Manager<TlsStream<TcpStream>, Error> for TlsConnection {
impl Manager for TlsConnection {
type Type = TlsStream<TcpStream>;
type Error = Error;

async fn create(&self) -> Result<TlsStream<TcpStream>, Error> {
let raw_stream = async_std::net::TcpStream::connect(self.addr).await?;

Expand Down