pub struct SocketConfig {Show 15 fields
pub url: String,
pub mode: Mode,
pub suffix: Vec<u8>,
pub message_handler: Option<TcpMessageHandler>,
pub heartbeat: Option<SocketHeartbeat>,
pub connect_timeout_ms: Option<u64>,
pub reconnect_delay_initial_ms: Option<u64>,
pub reconnect_delay_max_ms: Option<u64>,
pub reconnect_backoff_factor: Option<f64>,
pub reconnect_jitter_ms: Option<u64>,
pub connection_max_retries: Option<u32>,
pub reconnect_max_attempts: Option<u32>,
pub heartbeat_timeout_secs: Option<u64>,
pub writer_capacity: Option<usize>,
pub certs_dir: Option<String>,
}Expand description
Configuration for a TCP socket connection.
Fields§
§url: StringThe server address as host:port or a URL.
mode: ModeThe plain or TLS connection mode.
suffix: Vec<u8>The byte sequence that frames messages in both directions.
message_handler: Option<TcpMessageHandler>The function called for each complete incoming message.
heartbeat: Option<SocketHeartbeat>Optional application keepalive.
When set, the client sends SocketHeartbeat::payload every
SocketHeartbeat::interval_secs seconds. A raw socket has no Ping frames, so this type
requires a payload; the WebSocket Ping-frame case stays on
crate::websocket::WebSocketConfig::heartbeat_payload.
Each timing field carries the coarsest unit that expresses every legitimate value, and
quantities compared against each other share a unit: the interval and
Self::heartbeat_timeout_secs are bounded below by whole-second cadences, while reconnect
delays and jitter have real sub-second values and stay in milliseconds.
connect_timeout_ms: Option<u64>The timeout (milliseconds) for establishing a usable connection. Defaults to 10 seconds.
Bounds the initial connection attempt, each reconnect attempt, and how long a send waits for the client to become active again. Keep it above the reconnect backoff so a send does not give up part-way through a normal reconnect.
reconnect_delay_initial_ms: Option<u64>The initial reconnection delay (milliseconds) for reconnects.
reconnect_delay_max_ms: Option<u64>The maximum reconnect delay (milliseconds) for exponential backoff.
reconnect_backoff_factor: Option<f64>The exponential backoff factor for reconnection delays.
reconnect_jitter_ms: Option<u64>The maximum jitter (milliseconds) added to reconnection delays.
connection_max_retries: Option<u32>The maximum number of initial connection attempts. Defaults to 5.
reconnect_max_attempts: Option<u32>The maximum number of reconnection attempts before closing the client.
None: Unlimited reconnection attempts (default, recommended for production).Some(n): Transitions to CLOSED oncenconsecutive reconnect attempts have either failed or established connections active for less than 10 seconds.
heartbeat_timeout_secs: Option<u64>The dead-peer timeout (seconds) for the read task.
Seconds rather than milliseconds because this is a multiple of the heartbeat interval: it can never sensibly sit below one heartbeat cycle.
When set, the read task stops and triggers reconnection if no bytes at all arrive within
this duration. A raw socket has no control frames, so any inbound byte refreshes it,
including the venue’s reply to a heartbeat. That makes this the byte-level equivalent of
the WebSocket client’s heartbeat_timeout_secs, not of its idle_timeout_ms: there is
no transport-level way to tell keepalive traffic from data here.
None derives three heartbeat intervals when Self::heartbeat is set, and disables
detection otherwise. Some(0) is rejected. Set an explicit value above the heartbeat
interval so a healthy connection cannot trip it.
writer_capacity: Option<usize>The maximum number of outstanding messages, including queued, in-flight, and replay messages.
Defaults to 1,024. Sends fail immediately when full. Must be positive and no greater
than [tokio::sync::Semaphore::MAX_PERMITS]. This bounds message count, not payload bytes.
certs_dir: Option<String>The path to the certificates directory.
Every certificate that parses from any file directly inside the directory, regardless of
file name, becomes a trust anchor for the connection alongside the bundled webpki-roots
set. No CA or self-signature checks are performed. A certificate chain matched to a
private key in the directory is used as the client certificate instead. Write access to
the directory is therefore equivalent to control over which servers the connection
trusts. Restrict its contents to intended trust anchors. Each anchor loaded from it is
logged at INFO with its SHA-256 fingerprint.
Implementations§
Source§impl SocketConfig
impl SocketConfig
Sourcepub fn builder() -> SocketConfigBuilder
pub fn builder() -> SocketConfigBuilder
Create an instance of SocketConfig using the builder syntax
Source§impl SocketConfig
impl SocketConfig
Sourcepub fn validate(&self) -> NetworkConfigResult<()>
pub fn validate(&self) -> NetworkConfigResult<()>
Checks whether all socket settings are valid.
§Errors
Returns an error if url is empty, the heartbeat interval or a reconnection timing field is
not positive, reconnect_backoff_factor is outside [1.0, 100.0],
reconnect_delay_initial_ms exceeds reconnect_delay_max_ms, or writer_capacity is
outside [1, Semaphore::MAX_PERMITS].