pub struct ConnectionManager {
pub per_ip_semaphores: Arc<Mutex<HashMap<SocketAddr, Arc<Semaphore>>>>,
pub global_semaphore: Arc<Semaphore>,
pub stats: Arc<Mutex<HashMap<SocketAddr, ClientStats>>>,
pub config: ConnectionConfig,
pub total_connections: Arc<AtomicU64>,
pub total_requests: AtomicU64,
pub error_count: AtomicU32,
pub start_time: Instant,
pub response_times: Arc<Mutex<VecDeque<Duration>>>,
}
Expand description
TCP connection management
Fields§
§per_ip_semaphores: Arc<Mutex<HashMap<SocketAddr, Arc<Semaphore>>>>
Connection limit per IP
global_semaphore: Arc<Semaphore>
Global connection limit
stats: Arc<Mutex<HashMap<SocketAddr, ClientStats>>>
Stats per IP
config: ConnectionConfig
Configuration
total_connections: Arc<AtomicU64>
Counter of all connections
total_requests: AtomicU64
Total requests
error_count: AtomicU32
Error count
start_time: Instant
Start time
response_times: Arc<Mutex<VecDeque<Duration>>>
Response times
Implementations§
Source§impl Manager
impl Manager
pub fn new(config: ConnectionConfig) -> Self
Sourcepub async fn accept_connection(
self: &Arc<Self>,
addr: SocketAddr,
) -> Result<ConnectionGuard, RelayError>
pub async fn accept_connection( self: &Arc<Self>, addr: SocketAddr, ) -> Result<ConnectionGuard, RelayError>
Attempt to establish a new connection
pub async fn close_all_connections(&self) -> Result<(), RelayError>
pub async fn record_client_error( &self, addr: &SocketAddr, ) -> Result<(), RelayError>
Sourcepub async fn record_request(&self, addr: SocketAddr, success: bool)
pub async fn record_request(&self, addr: SocketAddr, success: bool)
Updates statistics for a given connection
Sourcepub async fn cleanup_idle_connections(&self) -> Result<(), RelayError>
pub async fn cleanup_idle_connections(&self) -> Result<(), RelayError>
Cleans up idle connections
Sourcepub async fn get_stats(&self) -> Result<ConnectionStats, RelayError>
pub async fn get_stats(&self) -> Result<ConnectionStats, RelayError>
Returns connection statistics
pub async fn connection_count(&self) -> u32
pub fn total_requests(&self) -> u64
pub fn error_count(&self) -> u32
pub async fn avg_response_time(&self) -> Duration
pub fn requests_per_second(&self) -> f64
pub fn record_requests(&self)
pub fn record_errors(&self)
pub async fn record_response_time(&self, duration: Duration)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Manager
impl !RefUnwindSafe for Manager
impl Send for Manager
impl Sync for Manager
impl Unpin for Manager
impl !UnwindSafe for Manager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more