1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 15:42:57 +01:00

Connector::Response returns addr and tcp stream

This commit is contained in:
Nikolay Kim 2018-08-27 14:20:41 -07:00
parent 3dbaef3ec1
commit c69d675113
4 changed files with 27 additions and 25 deletions

View File

@ -43,7 +43,7 @@ fn main() {
.unwrap();
let num = Arc::new(AtomicUsize::new(0));
let openssl = ssl::OpensslService::new(builder);
let openssl = ssl::OpensslAcceptor::new(builder);
// server start mutiple workers, it runs supplied `Fn` in each worker.
Server::default()
@ -51,9 +51,12 @@ fn main() {
let num = num.clone();
// configure service
openssl.clone().and_then((service, move || {
Ok::<_, io::Error>(ServiceState { num: num.clone() })
}))
openssl
.clone()
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
.and_then((service, move || {
Ok::<_, io::Error>(ServiceState { num: num.clone() })
}))
}).unwrap()
.start();

View File

@ -235,7 +235,7 @@ where
pub struct AndThenNewConfigurableService<A, B, C>
where
A: NewConfigurableService<C>,
B: NewConfigurableService<C>
B: NewConfigurableService<C>,
{
a: A,
b: B,
@ -259,11 +259,7 @@ where
impl<A, B, C> NewConfigurableService<C> for AndThenNewConfigurableService<A, B, C>
where
A: NewConfigurableService<
C,
Response = B::Request,
InitError = B::InitError,
>,
A: NewConfigurableService<C, Response = B::Request, InitError = B::InitError>,
A::Error: Into<B::Error>,
B: NewConfigurableService<C>,
C: Clone,
@ -359,7 +355,7 @@ where
/// `MapErrNewService` new service combinator
pub struct MapErrNewConfigurableService<A, F, E, C>
where
A: NewConfigurableService<C>
A: NewConfigurableService<C>,
{
a: A,
f: F,
@ -455,7 +451,7 @@ where
/// `MapInitErr` service combinator
pub struct MapInitErr<A, F, E, C>
where
A: NewConfigurableService<C>
A: NewConfigurableService<C>,
{
a: A,
f: F,

View File

@ -51,7 +51,7 @@ impl Connector {
impl Service for Connector {
type Request = String;
type Response = TcpStream;
type Response = (String, TcpStream);
type Error = ConnectorError;
type Future = ConnectorFuture;
@ -60,25 +60,32 @@ impl Service for Connector {
}
fn call(&mut self, addr: String) -> Self::Future {
let fut = ResolveFut::new(&addr, 0, &self.resolver);
ConnectorFuture {
fut: ResolveFut::new(addr, 0, &self.resolver),
fut,
addr: Some(addr),
fut2: None,
}
}
}
pub struct ConnectorFuture {
addr: Option<String>,
fut: ResolveFut,
fut2: Option<TcpConnector>,
}
impl Future for ConnectorFuture {
type Item = TcpStream;
type Item = (String, TcpStream);
type Error = ConnectorError;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
if let Some(ref mut fut) = self.fut2 {
return fut.poll();
return match fut.poll()? {
Async::Ready(stream) => Ok(Async::Ready((self.addr.take().unwrap(), stream))),
Async::NotReady => Ok(Async::NotReady),
};
}
match self.fut.poll()? {
Async::Ready(addrs) => {
@ -100,7 +107,7 @@ struct ResolveFut {
}
impl ResolveFut {
pub fn new(addr: String, port: u16, resolver: &AsyncResolver) -> Self {
pub fn new(addr: &str, port: u16, resolver: &AsyncResolver) -> Self {
// we need to do dns resolution
match ResolveFut::parse(addr.as_ref(), port) {
Ok((host, port)) => ResolveFut {

View File

@ -115,7 +115,7 @@ impl<T> Clone for OpensslConnector<T> {
}
impl<T: AsyncRead + AsyncWrite> NewService for OpensslConnector<T> {
type Request = T;
type Request = (String, T);
type Response = SslStream<T>;
type Error = Error;
type Service = OpensslConnectorService<T>;
@ -130,17 +130,13 @@ impl<T: AsyncRead + AsyncWrite> NewService for OpensslConnector<T> {
}
}
pub trait OpensslDomain {
fn domain(&self) -> &str;
}
pub struct OpensslConnectorService<T> {
connector: SslConnector,
io: PhantomData<T>,
}
impl<T: AsyncRead + AsyncWrite> Service for OpensslConnectorService<T> {
type Request = T;
type Request = (String, T);
type Response = SslStream<T>;
type Error = Error;
type Future = ConnectAsync<T>;
@ -149,7 +145,7 @@ impl<T: AsyncRead + AsyncWrite> Service for OpensslConnectorService<T> {
Ok(Async::Ready(()))
}
fn call(&mut self, req: Self::Request) -> Self::Future {
SslConnectorExt::connect_async(&self.connector, "", req)
fn call(&mut self, (host, stream): Self::Request) -> Self::Future {
SslConnectorExt::connect_async(&self.connector, &host, stream)
}
}