Skip to main content

actori_tls/
lib.rs

1//! SSL Services
2#![deny(rust_2018_idioms, warnings)]
3#![allow(clippy::type_complexity)]
4
5use std::sync::atomic::{AtomicUsize, Ordering};
6
7use actori_utils::counter::Counter;
8
9#[cfg(feature = "openssl")]
10pub mod openssl;
11
12#[cfg(feature = "rustls")]
13pub mod rustls;
14
15#[cfg(feature = "nativetls")]
16pub mod nativetls;
17
18/// Sets the maximum per-worker concurrent ssl connection establish process.
19///
20/// All listeners will stop accepting connections when this limit is
21/// reached. It can be used to limit the global SSL CPU usage.
22///
23/// By default max connections is set to a 256.
24pub fn max_concurrent_ssl_connect(num: usize) {
25    MAX_CONN.store(num, Ordering::Relaxed);
26}
27
28pub(crate) static MAX_CONN: AtomicUsize = AtomicUsize::new(256);
29
30thread_local! {
31    static MAX_CONN_COUNTER: Counter = Counter::new(MAX_CONN.load(Ordering::Relaxed));
32}
33
34/// Ssl error combinded with service error.
35#[derive(Debug)]
36pub enum SslError<E1, E2> {
37    Ssl(E1),
38    Service(E2),
39}