pub struct ConnectionConfig { /* private fields */ }Expand description
Connection timeout configuration
This struct defines the timeout settings for WebSocket connections to prevent resource exhaustion from idle connections.
§Fields
idle_timeout- Maximum duration a connection can be idle before being closed (default: 5 minutes)handshake_timeout- Maximum duration for the WebSocket handshake to complete (default: 10 seconds)cleanup_interval- Interval for checking idle connections (default: 30 seconds)
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
use std::time::Duration;
let config = ConnectionConfig::new()
.with_idle_timeout(Duration::from_secs(300))
.with_handshake_timeout(Duration::from_secs(10))
.with_cleanup_interval(Duration::from_secs(30));
assert_eq!(config.idle_timeout(), Duration::from_secs(300));
assert_eq!(config.handshake_timeout(), Duration::from_secs(10));
assert_eq!(config.cleanup_interval(), Duration::from_secs(30));Implementations§
Source§impl ConnectionConfig
impl ConnectionConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new connection configuration with default values
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
use std::time::Duration;
let config = ConnectionConfig::new();
assert_eq!(config.idle_timeout(), Duration::from_secs(300));
assert_eq!(config.handshake_timeout(), Duration::from_secs(10));
assert_eq!(config.cleanup_interval(), Duration::from_secs(30));Sourcepub fn with_idle_timeout(self, timeout: Duration) -> Self
pub fn with_idle_timeout(self, timeout: Duration) -> Self
Set the idle timeout duration
§Arguments
timeout- Maximum duration a connection can be idle before being closed
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
use std::time::Duration;
let config = ConnectionConfig::new()
.with_idle_timeout(Duration::from_secs(60));
assert_eq!(config.idle_timeout(), Duration::from_secs(60));Sourcepub fn with_handshake_timeout(self, timeout: Duration) -> Self
pub fn with_handshake_timeout(self, timeout: Duration) -> Self
Set the handshake timeout duration
§Arguments
timeout- Maximum duration for the WebSocket handshake to complete
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
use std::time::Duration;
let config = ConnectionConfig::new()
.with_handshake_timeout(Duration::from_secs(5));
assert_eq!(config.handshake_timeout(), Duration::from_secs(5));Sourcepub fn with_cleanup_interval(self, interval: Duration) -> Self
pub fn with_cleanup_interval(self, interval: Duration) -> Self
Set the cleanup interval for checking idle connections
§Arguments
interval- How often to check for idle connections
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
use std::time::Duration;
let config = ConnectionConfig::new()
.with_cleanup_interval(Duration::from_secs(15));
assert_eq!(config.cleanup_interval(), Duration::from_secs(15));Sourcepub fn idle_timeout(&self) -> Duration
pub fn idle_timeout(&self) -> Duration
Get the idle timeout duration
Sourcepub fn handshake_timeout(&self) -> Duration
pub fn handshake_timeout(&self) -> Duration
Get the handshake timeout duration
Sourcepub fn cleanup_interval(&self) -> Duration
pub fn cleanup_interval(&self) -> Duration
Get the cleanup interval duration
Sourcepub fn with_max_connections(self, max: Option<usize>) -> Self
pub fn with_max_connections(self, max: Option<usize>) -> Self
Set the maximum number of concurrent connections
§Arguments
max- Maximum number of connections allowed. UseNonefor unlimited.
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
let config = ConnectionConfig::new()
.with_max_connections(Some(1000));
assert_eq!(config.max_connections(), Some(1000));Sourcepub fn max_connections(&self) -> Option<usize>
pub fn max_connections(&self) -> Option<usize>
Get the maximum number of concurrent connections
Sourcepub fn with_ping_config(self, config: PingPongConfig) -> Self
pub fn with_ping_config(self, config: PingPongConfig) -> Self
Set the ping/pong keepalive configuration.
§Arguments
config- The ping/pong configuration to use
§Examples
use reinhardt_websockets::connection::{ConnectionConfig, PingPongConfig};
use std::time::Duration;
let ping_config = PingPongConfig::new(
Duration::from_secs(15),
Duration::from_secs(5),
);
let config = ConnectionConfig::new()
.with_ping_config(ping_config);
assert_eq!(config.ping_config().ping_interval(), Duration::from_secs(15));
assert_eq!(config.ping_config().pong_timeout(), Duration::from_secs(5));Sourcepub fn ping_config(&self) -> &PingPongConfig
pub fn ping_config(&self) -> &PingPongConfig
Get the ping/pong keepalive configuration.
Sourcepub fn no_timeout() -> Self
pub fn no_timeout() -> Self
Create a configuration with no idle timeout (connections never time out)
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
let config = ConnectionConfig::no_timeout();
assert_eq!(config.idle_timeout(), std::time::Duration::MAX);
assert_eq!(config.handshake_timeout(), std::time::Duration::MAX);Sourcepub fn strict() -> Self
pub fn strict() -> Self
Create a strict configuration with short timeouts
- Idle timeout: 30 seconds
- Handshake timeout: 5 seconds
- Cleanup interval: 10 seconds
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
use std::time::Duration;
let config = ConnectionConfig::strict();
assert_eq!(config.idle_timeout(), Duration::from_secs(30));
assert_eq!(config.handshake_timeout(), Duration::from_secs(5));
assert_eq!(config.cleanup_interval(), Duration::from_secs(10));Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive configuration with long timeouts
- Idle timeout: 1 hour
- Handshake timeout: 30 seconds
- Cleanup interval: 60 seconds
§Examples
use reinhardt_websockets::connection::ConnectionConfig;
use std::time::Duration;
let config = ConnectionConfig::permissive();
assert_eq!(config.idle_timeout(), Duration::from_secs(3600));
assert_eq!(config.handshake_timeout(), Duration::from_secs(30));
assert_eq!(config.cleanup_interval(), Duration::from_secs(60));Trait Implementations§
Source§impl Clone for ConnectionConfig
impl Clone for ConnectionConfig
Source§fn clone(&self) -> ConnectionConfig
fn clone(&self) -> ConnectionConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more