include/entropic/mcp/reconnect_policy.h¶
include/entropic/mcp/reconnect_policy.h
entropic::ReconnectPolicy
Exponential backoff with jitter for reconnection attempts.
entropic::ReconnectPolicy::ReconnectPolicy(uint32_t base_delay_ms=1000, uint32_t max_delay_ms=60000, uint32_t max_retries=5, double backoff_factor=2.0)
Construct with explicit parameters.
- Parameters
base_delay_ms— Base delay in milliseconds.max_delay_ms— Maximum delay cap.max_retries— Maximum attempts (0 = infinite).backoff_factor— Multiplicative factor per attempt.base_delay_ms— Base delay.backoff_factor— Exponential multiplier.
entropic::ReconnectPolicy::ReconnectPolicy(const ReconnectConfig &config)
Construct from config struct.
- Parameters
config— ReconnectConfig with all parameters.config— ReconnectConfig.
uint32_t entropic::ReconnectPolicy::delay_ms(uint32_t attempt) const
Compute delay for the given attempt number.
Compute delay with exponential backoff and jitter.
- Parameters
attempt— Zero-based attempt number.
- Returns
- Delay in milliseconds (with jitter).
- base_delay * factor^attempt, capped at max_delay, plus a uniform jitter of up to 10% of the capped value — so delay grows exponentially, saturates at max_delay, and repeated reconnects across servers do not synchronise.
bool entropic::ReconnectPolicy::exhausted(uint32_t attempt) const
Check if retries are exhausted.
- Parameters
attempt— Zero-based attempt number.
- Returns
- true if max_retries > 0 and attempt >= max_retries.
- true once attempt reaches max_retries; always false when max_retries is 0, which means "retry forever".