1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-22 16:16:40 +00:00

add DefaultConnector

This commit is contained in:
Nikolay Kim 2018-09-10 10:59:35 -07:00
parent 3fe029a8ad
commit fbfca66e21
2 changed files with 46 additions and 0 deletions

View file

@ -150,6 +150,51 @@ impl<T: HostAware> Future for ConnectorFuture<T> {
} }
} }
pub struct DefaultConnector<T: HostAware>(Connector<T>);
impl<T: HostAware> Default for DefaultConnector<T> {
fn default() -> Self {
DefaultConnector(Connector::default())
}
}
impl<T: HostAware> DefaultConnector<T> {
pub fn new(cfg: ResolverConfig, opts: ResolverOpts) -> Self {
DefaultConnector(Connector::new(cfg, opts))
}
}
impl<T: HostAware> Service for DefaultConnector<T> {
type Request = T;
type Response = TcpStream;
type Error = ConnectorError;
type Future = DefaultConnectorFuture<T>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
self.0.poll_ready()
}
fn call(&mut self, req: Self::Request) -> Self::Future {
DefaultConnectorFuture {
fut: self.0.call(req),
}
}
}
#[doc(hidden)]
pub struct DefaultConnectorFuture<T: HostAware> {
fut: ConnectorFuture<T>,
}
impl<T: HostAware> Future for DefaultConnectorFuture<T> {
type Item = TcpStream;
type Error = ConnectorError;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
Ok(Async::Ready(try_ready!(self.fut.poll()).2))
}
}
/// Resolver future /// Resolver future
struct ResolveFut<T> { struct ResolveFut<T> {
req: Option<T>, req: Option<T>,

View file

@ -21,6 +21,7 @@ extern crate log;
extern crate bytes; extern crate bytes;
#[macro_use] #[macro_use]
extern crate failure; extern crate failure;
#[macro_use]
extern crate futures; extern crate futures;
extern crate mio; extern crate mio;
extern crate net2; extern crate net2;