mirror of
https://github.com/fafhrd91/actix-net
synced 2025-02-20 06:30:32 +01:00
add TlsError::into_service_error
(#420)
This commit is contained in:
parent
3597af5c45
commit
67b357a175
@ -4,8 +4,10 @@
|
|||||||
* Add configurable timeout for accepting TLS connection. [#393]
|
* Add configurable timeout for accepting TLS connection. [#393]
|
||||||
* Added `TlsError::Timeout` variant. [#393]
|
* Added `TlsError::Timeout` variant. [#393]
|
||||||
* All TLS acceptor services now use `TlsError` for their error types. [#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
|
[#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
|
## 3.0.0-beta.8 - 2021-11-15
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
//! TLS acceptor services.
|
//! TLS acceptor services.
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::{
|
||||||
|
convert::Infallible,
|
||||||
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
|
};
|
||||||
|
|
||||||
use actix_utils::counter::Counter;
|
use actix_utils::counter::Counter;
|
||||||
|
|
||||||
@ -36,7 +39,29 @@ pub fn max_concurrent_tls_connect(num: usize) {
|
|||||||
/// TLS error combined with service error.
|
/// TLS error combined with service error.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum TlsError<TlsErr, SvcErr> {
|
pub enum TlsError<TlsErr, SvcErr> {
|
||||||
Tls(TlsErr),
|
|
||||||
Timeout,
|
Timeout,
|
||||||
|
Tls(TlsErr),
|
||||||
Service(SvcErr),
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -134,7 +134,6 @@ impl<T: ActixStream + 'static> ServiceFactory<T> for Acceptor {
|
|||||||
type Response = TlsStream<T>;
|
type Response = TlsStream<T>;
|
||||||
type Error = TlsError<Error, Infallible>;
|
type Error = TlsError<Error, Infallible>;
|
||||||
type Config = ();
|
type Config = ();
|
||||||
|
|
||||||
type Service = NativeTlsAcceptorService;
|
type Service = NativeTlsAcceptorService;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
||||||
|
@ -138,7 +138,6 @@ impl<T: ActixStream> ServiceFactory<T> for Acceptor {
|
|||||||
type Response = TlsStream<T>;
|
type Response = TlsStream<T>;
|
||||||
type Error = TlsError<io::Error, Infallible>;
|
type Error = TlsError<io::Error, Infallible>;
|
||||||
type Config = ();
|
type Config = ();
|
||||||
|
|
||||||
type Service = AcceptorService;
|
type Service = AcceptorService;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
||||||
|
@ -115,7 +115,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum RustlsConnectorServiceFuture<T, U> {
|
pub enum RustlsConnectorServiceFuture<T, U> {
|
||||||
/// See issue https://github.com/briansmith/webpki/issues/54
|
/// See issue <https://github.com/briansmith/webpki/issues/54>
|
||||||
InvalidDns,
|
InvalidDns,
|
||||||
Future {
|
Future {
|
||||||
connect: Connect<U>,
|
connect: Connect<U>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user