Skip to content

Commit

Permalink
rework client connection pool (#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow committed Feb 16, 2021
1 parent 55db3ec commit c065729
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 481 deletions.
5 changes: 5 additions & 0 deletions actix-http/CHANGES.md
Expand Up @@ -4,7 +4,12 @@
### Changed
* Feature `cookies` is now optional and disabled by default. [#1981]

### Removed
* re-export of `futures_channel::oneshot::Canceled` is removed from `error` mod. [#1994]
* `ResponseError` impl for `futures_channel::oneshot::Canceled` is removed. [#1994]

[#1981]: https://github.com/actix/actix-web/pull/1981
[#1994]: https://github.com/actix/actix-web/pull/1994


## 3.0.0-beta.3 - 2021-02-10
Expand Down
4 changes: 1 addition & 3 deletions actix-http/Cargo.toml
Expand Up @@ -59,13 +59,11 @@ cfg-if = "1"
cookie = { version = "0.14.1", features = ["percent-encode"], optional = true }
derive_more = "0.99.5"
encoding_rs = "0.8"
futures-channel = { version = "0.3.7", default-features = false, features = ["alloc"] }
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
futures-util = { version = "0.3.7", default-features = false, features = ["alloc", "sink"] }
h2 = "0.3.0"
http = "0.2.2"
httparse = "1.3"
indexmap = "1.3"
itoa = "0.4"
language-tags = "0.2"
lazy_static = "1.4"
Expand All @@ -79,9 +77,9 @@ serde = "1.0"
serde_json = "1.0"
serde_urlencoded = "0.7"
sha-1 = "0.9"
slab = "0.4"
smallvec = "1.6"
time = { version = "0.2.23", default-features = false, features = ["std"] }
tokio = { version = "1.2", features = ["sync"] }

# compression
brotli2 = { version="0.3.2", optional = true }
Expand Down
18 changes: 15 additions & 3 deletions actix-http/src/client/connection.rs
Expand Up @@ -103,15 +103,18 @@ pub(crate) trait ConnectionLifetime: AsyncRead + AsyncWrite + 'static {

#[doc(hidden)]
/// HTTP client connection
pub struct IoConnection<T> {
pub struct IoConnection<T>
where
T: AsyncWrite + Unpin + 'static,
{
io: Option<ConnectionType<T>>,
created: time::Instant,
pool: Option<Acquired<T>>,
}

impl<T> fmt::Debug for IoConnection<T>
where
T: fmt::Debug,
T: AsyncWrite + Unpin + fmt::Debug + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.io {
Expand All @@ -138,6 +141,11 @@ impl<T: AsyncRead + AsyncWrite + Unpin> IoConnection<T> {
pub(crate) fn into_inner(self) -> (ConnectionType<T>, time::Instant) {
(self.io.unwrap(), self.created)
}

#[cfg(test)]
pub(crate) fn into_parts(self) -> (ConnectionType<T>, time::Instant, Acquired<T>) {
(self.io.unwrap(), self.created, self.pool.unwrap())
}
}

impl<T> Connection for IoConnection<T>
Expand Down Expand Up @@ -202,7 +210,11 @@ where
}

#[allow(dead_code)]
pub(crate) enum EitherConnection<A, B> {
pub(crate) enum EitherConnection<A, B>
where
A: AsyncRead + AsyncWrite + Unpin + 'static,
B: AsyncRead + AsyncWrite + Unpin + 'static,
{
A(IoConnection<A>),
B(IoConnection<B>),
}
Expand Down
5 changes: 4 additions & 1 deletion actix-http/src/client/h1proto.rs
Expand Up @@ -165,7 +165,10 @@ where

#[doc(hidden)]
/// HTTP client connection
pub struct H1Connection<T> {
pub struct H1Connection<T>
where
T: AsyncWrite + Unpin + 'static,
{
/// T should be `Unpin`
io: Option<T>,
created: time::Instant,
Expand Down

0 comments on commit c065729

Please sign in to comment.