2020-09-08 18:00:07 +01:00
|
|
|
//! TLS acceptor services for Actix ecosystem.
|
|
|
|
//!
|
|
|
|
//! ## Crate Features
|
|
|
|
//! * `openssl` - TLS acceptor using the `openssl` crate.
|
|
|
|
//! * `rustls` - TLS acceptor using the `rustls` crate.
|
|
|
|
//! * `nativetls` - TLS acceptor using the `native-tls` crate.
|
|
|
|
|
2020-12-12 23:24:00 +00:00
|
|
|
#![deny(rust_2018_idioms, nonstandard_style)]
|
|
|
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
|
|
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
2019-12-02 22:30:09 +06:00
|
|
|
|
2019-12-02 11:30:27 +06:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
|
|
|
use actix_utils::counter::Counter;
|
|
|
|
|
|
|
|
#[cfg(feature = "openssl")]
|
|
|
|
pub mod openssl;
|
|
|
|
|
2019-12-05 20:52:37 +06:00
|
|
|
#[cfg(feature = "rustls")]
|
|
|
|
pub mod rustls;
|
|
|
|
|
|
|
|
#[cfg(feature = "nativetls")]
|
|
|
|
pub mod nativetls;
|
2019-12-02 11:30:27 +06:00
|
|
|
|
|
|
|
pub(crate) static MAX_CONN: AtomicUsize = AtomicUsize::new(256);
|
|
|
|
|
|
|
|
thread_local! {
|
|
|
|
static MAX_CONN_COUNTER: Counter = Counter::new(MAX_CONN.load(Ordering::Relaxed));
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:00:07 +01:00
|
|
|
/// Sets the maximum per-worker concurrent TLS connection limit.
|
|
|
|
///
|
|
|
|
/// All listeners will stop accepting connections when this limit is reached.
|
|
|
|
/// It can be used to regulate the global TLS CPU usage.
|
|
|
|
///
|
|
|
|
/// By default, the connection limit is 256.
|
|
|
|
pub fn max_concurrent_tls_connect(num: usize) {
|
|
|
|
MAX_CONN.store(num, Ordering::Relaxed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// TLS error combined with service error.
|
2019-12-02 11:30:27 +06:00
|
|
|
#[derive(Debug)]
|
2020-09-08 18:00:07 +01:00
|
|
|
pub enum TlsError<E1, E2> {
|
|
|
|
Tls(E1),
|
2019-12-02 11:30:27 +06:00
|
|
|
Service(E2),
|
|
|
|
}
|