Skip to content

Commit

Permalink
connector: Add unix feature
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayknarayan committed Nov 19, 2019
1 parent 354d4fd commit 02defcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ transport = [
]
tls = ["tokio-rustls"]
tls-roots = ["rustls-native-certs"]
unix = [
"hyper-unix-connector", "transport"
]

[[bench]]
name = "bench_main"
Expand Down Expand Up @@ -69,6 +72,9 @@ tower-make = "=0.3.0-alpha.2a"
tower-balance = { version = "=0.3.0-alpha.2", optional = true }
tower-load = { version = "=0.3.0-alpha.2", optional = true }

# unix
hyper-unix-connector = { version = "0.1.1", optional = true }

# rustls
tokio-rustls = { version = "=0.12.0-alpha.5", optional = true }
rustls-native-certs = { version = "0.1", optional = true }
Expand Down
11 changes: 9 additions & 2 deletions tonic/src/transport/service/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ use super::io::BoxedIo;
use super::tls::TlsConnector;
use http::Uri;
use hyper::client::connect::HttpConnector;
#[cfg(feature = "unix")]
use hyper_unix_connector::UnixClient;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use tower_make::MakeConnection;
use tower_service::Service;

#[cfg(not(feature = "tls"))]
#[cfg(all(not(feature = "unix"), not(feature = "tls")))]
pub(crate) fn connector() -> HttpConnector {
let mut http = HttpConnector::new();
http.enforce_http(false);
http.set_nodelay(true);
http
}

#[cfg(feature = "tls")]
#[cfg(all(feature = "unix", not(feature = "tls")))]
pub(crate) fn connector() -> UnixClient {
UnixClient
}

#[cfg(all(feature = "tls", not(feature = "unix")))]
pub(crate) fn connector(tls: Option<TlsConnector>) -> Connector {
Connector::new(tls)
}
Expand Down

0 comments on commit 02defcd

Please sign in to comment.