bolar_2 backup
This commit is contained in:
35
main/connectivity/reconnect_backoff.h
Normal file
35
main/connectivity/reconnect_backoff.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace borla {
|
||||
|
||||
struct ReconnectBackoffConfig {
|
||||
uint32_t initial_delay_ms = 1000;
|
||||
uint32_t maximum_delay_ms = 60000;
|
||||
uint8_t multiplier = 2;
|
||||
uint8_t jitter_percent = 20;
|
||||
};
|
||||
|
||||
class ReconnectBackoff final {
|
||||
public:
|
||||
explicit ReconnectBackoff(
|
||||
ReconnectBackoffConfig config = ReconnectBackoffConfig{});
|
||||
|
||||
uint32_t NextDelayMs(uint32_t entropy);
|
||||
void Reset();
|
||||
|
||||
uint32_t attempt_count() const { return attempt_count_; }
|
||||
uint32_t current_base_delay_ms() const { return current_base_delay_ms_; }
|
||||
const ReconnectBackoffConfig& config() const { return config_; }
|
||||
|
||||
private:
|
||||
static ReconnectBackoffConfig Normalize(
|
||||
ReconnectBackoffConfig config);
|
||||
|
||||
ReconnectBackoffConfig config_;
|
||||
uint32_t current_base_delay_ms_ = 0;
|
||||
uint32_t attempt_count_ = 0;
|
||||
};
|
||||
|
||||
} // namespace borla
|
||||
Reference in New Issue
Block a user