1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-31 12:42:09 +01:00

use service types for ssl connectors

This commit is contained in:
Nikolay Kim 2019-11-18 20:20:56 +06:00
parent 1354946460
commit 877f89eeb7
2 changed files with 20 additions and 21 deletions

View File

@ -36,13 +36,7 @@ where
T: Address + Unpin + 'static, T: Address + Unpin + 'static,
U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static,
{ {
pub fn service( pub fn service(connector: SslConnector) -> OpensslConnectorService<T, U> {
connector: SslConnector,
) -> impl Service<
Request = Connection<T, U>,
Response = Connection<T, SslStream<U>>,
Error = io::Error,
> {
OpensslConnectorService { OpensslConnectorService {
connector: connector, connector: connector,
_t: PhantomData, _t: PhantomData,
@ -59,8 +53,9 @@ impl<T, U> Clone for OpensslConnector<T, U> {
} }
} }
impl<T: Address + Unpin + 'static, U> ServiceFactory for OpensslConnector<T, U> impl<T, U> ServiceFactory for OpensslConnector<T, U>
where where
T: Address + 'static,
U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static,
{ {
type Request = Connection<T, U>; type Request = Connection<T, U>;
@ -93,8 +88,9 @@ impl<T, U> Clone for OpensslConnectorService<T, U> {
} }
} }
impl<T: Address + Unpin + 'static, U> Service for OpensslConnectorService<T, U> impl<T, U> Service for OpensslConnectorService<T, U>
where where
T: Address + 'static,
U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static,
{ {
type Request = Connection<T, U>; type Request = Connection<T, U>;
@ -129,7 +125,7 @@ pub struct ConnectAsyncExt<T, U> {
_t: PhantomData<U>, _t: PhantomData<U>,
} }
impl<T: Address + Unpin, U> Future for ConnectAsyncExt<T, U> impl<T: Address, U> Future for ConnectAsyncExt<T, U>
where where
U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static,
{ {
@ -196,7 +192,7 @@ impl<T> Clone for OpensslConnectServiceFactory<T> {
} }
} }
impl<T: Address + Unpin + 'static> ServiceFactory for OpensslConnectServiceFactory<T> { impl<T: Address + 'static> ServiceFactory for OpensslConnectServiceFactory<T> {
type Request = Connect<T>; type Request = Connect<T>;
type Response = SslStream<TcpStream>; type Response = SslStream<TcpStream>;
type Error = ConnectError; type Error = ConnectError;
@ -216,7 +212,7 @@ pub struct OpensslConnectService<T> {
openssl: OpensslConnectorService<T, TcpStream>, openssl: OpensslConnectorService<T, TcpStream>,
} }
impl<T: Address + Unpin + 'static> Service for OpensslConnectService<T> { impl<T: Address + 'static> Service for OpensslConnectService<T> {
type Request = Connect<T>; type Request = Connect<T>;
type Response = SslStream<TcpStream>; type Response = SslStream<TcpStream>;
type Error = ConnectError; type Error = ConnectError;
@ -235,13 +231,13 @@ impl<T: Address + Unpin + 'static> Service for OpensslConnectService<T> {
} }
} }
pub struct OpensslConnectServiceResponse<T: Address + Unpin + 'static> { pub struct OpensslConnectServiceResponse<T: Address + 'static> {
fut1: Option<<ConnectService<T> as Service>::Future>, fut1: Option<<ConnectService<T> as Service>::Future>,
fut2: Option<<OpensslConnectorService<T, TcpStream> as Service>::Future>, fut2: Option<<OpensslConnectorService<T, TcpStream> as Service>::Future>,
openssl: OpensslConnectorService<T, TcpStream>, openssl: OpensslConnectorService<T, TcpStream>,
} }
impl<T: Address + Unpin> Future for OpensslConnectServiceResponse<T> { impl<T: Address> Future for OpensslConnectServiceResponse<T> {
type Output = Result<SslStream<TcpStream>, ConnectError>; type Output = Result<SslStream<TcpStream>, ConnectError>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {

View File

@ -33,13 +33,7 @@ where
T: Address + Unpin, T: Address + Unpin,
U: AsyncRead + AsyncWrite + Unpin + fmt::Debug, U: AsyncRead + AsyncWrite + Unpin + fmt::Debug,
{ {
pub fn service( pub fn service(connector: Arc<ClientConfig>) -> RustlsConnectorService<T, U> {
connector: Arc<ClientConfig>,
) -> impl Service<
Request = Connection<T, U>,
Response = Connection<T, TlsStream<U>>,
Error = std::io::Error,
> {
RustlsConnectorService { RustlsConnectorService {
connector: connector, connector: connector,
_t: PhantomData, _t: PhantomData,
@ -81,6 +75,15 @@ pub struct RustlsConnectorService<T, U> {
_t: PhantomData<(T, U)>, _t: PhantomData<(T, U)>,
} }
impl<T, U> Clone for RustlsConnectorService<T, U> {
fn clone(&self) -> Self {
Self {
connector: self.connector.clone(),
_t: PhantomData,
}
}
}
impl<T: Address + Unpin, U> Service for RustlsConnectorService<T, U> impl<T: Address + Unpin, U> Service for RustlsConnectorService<T, U>
where where
U: AsyncRead + AsyncWrite + Unpin + fmt::Debug, U: AsyncRead + AsyncWrite + Unpin + fmt::Debug,