Skip to main content

ConnectionConfig

Struct ConnectionConfig 

Source
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

Source

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));
Source

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));
Source

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));
Source

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));
Source

pub fn idle_timeout(&self) -> Duration

Get the idle timeout duration

Source

pub fn handshake_timeout(&self) -> Duration

Get the handshake timeout duration

Source

pub fn cleanup_interval(&self) -> Duration

Get the cleanup interval duration

Source

pub fn with_max_connections(self, max: Option<usize>) -> Self

Set the maximum number of concurrent connections

§Arguments
  • max - Maximum number of connections allowed. Use None for unlimited.
§Examples
use reinhardt_websockets::connection::ConnectionConfig;

let config = ConnectionConfig::new()
    .with_max_connections(Some(1000));

assert_eq!(config.max_connections(), Some(1000));
Source

pub fn max_connections(&self) -> Option<usize>

Get the maximum number of concurrent connections

Source

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));
Source

pub fn ping_config(&self) -> &PingPongConfig

Get the ping/pong keepalive configuration.

Source

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);
Source

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));
Source

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

Source§

fn clone(&self) -> ConnectionConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConnectionConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConnectionConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V