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

add TlsError::into_service_error (#420)

This commit is contained in:
Rob Ede 2021-11-22 13:33:20 +00:00 committed by GitHub
parent 3597af5c45
commit 67b357a175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 5 deletions

View File

@ -4,8 +4,10 @@
* Add configurable timeout for accepting TLS connection. [#393]
* Added `TlsError::Timeout` variant. [#393]
* All TLS acceptor services now use `TlsError` for their error types. [#393]
* Added `TlsError::into_service_error`. [#420]
[#393]: https://github.com/actix/actix-net/pull/393
[#420]: https://github.com/actix/actix-net/pull/420
## 3.0.0-beta.8 - 2021-11-15

View File

@ -1,6 +1,9 @@
//! TLS acceptor services.
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{
convert::Infallible,
sync::atomic::{AtomicUsize, Ordering},
};
use actix_utils::counter::Counter;
@ -36,7 +39,29 @@ pub fn max_concurrent_tls_connect(num: usize) {
/// TLS error combined with service error.
#[derive(Debug)]
pub enum TlsError<TlsErr, SvcErr> {
Tls(TlsErr),
Timeout,
Tls(TlsErr),
Service(SvcErr),
}
impl<TlsErr> TlsError<TlsErr, Infallible> {
/// Casts the infallible service error type returned from acceptors into caller's type.
pub fn into_service_error<SvcErr>(self) -> TlsError<TlsErr, SvcErr> {
match self {
Self::Timeout => TlsError::Timeout,
Self::Tls(err) => TlsError::Tls(err),
Self::Service(_) => unreachable!(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tls_service_error_inference() {
let a: TlsError<u32, Infallible> = TlsError::Tls(42);
let _b: TlsError<u32, u64> = a.into_service_error();
}
}

View File

@ -134,7 +134,6 @@ impl<T: ActixStream + 'static> ServiceFactory<T> for Acceptor {
type Response = TlsStream<T>;
type Error = TlsError<Error, Infallible>;
type Config = ();
type Service = NativeTlsAcceptorService;
type InitError = ();
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;

View File

@ -138,7 +138,6 @@ impl<T: ActixStream> ServiceFactory<T> for Acceptor {
type Response = TlsStream<T>;
type Error = TlsError<io::Error, Infallible>;
type Config = ();
type Service = AcceptorService;
type InitError = ();
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;

View File

@ -115,7 +115,7 @@ where
}
pub enum RustlsConnectorServiceFuture<T, U> {
/// See issue https://github.com/briansmith/webpki/issues/54
/// See issue <https://github.com/briansmith/webpki/issues/54>
InvalidDns,
Future {
connect: Connect<U>,