@@ -37,6 +37,13 @@ auto const kDefaultUserAgent = BOOST_BEAST_VERSION_STRING;
37
37
// Time duration used when no timeout is specified (1 year).
38
38
auto const kNoTimeout = std::chrono::hours(8760 );
39
39
40
+ // Time duration that the backoff algorithm uses before initiating a new
41
+ // connection, the first time a failure is detected.
42
+ auto const kDefaultInitialReconnectDelay = std::chrono::seconds(1 );
43
+
44
+ // Maximum duration between backoff attempts.
45
+ auto const kDefaultMaxBackoffDelay = std::chrono::seconds(30 );
46
+
40
47
static boost::optional<net::ssl::context&> ToOptRef (
41
48
std::optional<net::ssl::context>& maybe_val) {
42
49
if (maybe_val) {
@@ -60,6 +67,7 @@ class FoxyClient : public Client,
60
67
std::optional<std::chrono::milliseconds> connect_timeout,
61
68
std::optional<std::chrono::milliseconds> read_timeout,
62
69
std::optional<std::chrono::milliseconds> write_timeout,
70
+ std::optional<std::chrono::milliseconds> initial_reconnect_delay,
63
71
Builder::EventReceiver receiver,
64
72
Builder::LogCallback logger,
65
73
Builder::ErrorCallback errors,
@@ -75,7 +83,9 @@ class FoxyClient : public Client,
75
83
launchdarkly::foxy::session_opts{
76
84
ToOptRef (ssl_context_),
77
85
connect_timeout.value_or (kNoTimeout )}),
78
- backoff_ (std::chrono::seconds(1 ), std::chrono::seconds(30 )),
86
+ backoff_ (
87
+ initial_reconnect_delay.value_or(kDefaultInitialReconnectDelay ),
88
+ kDefaultMaxBackoffDelay),
79
89
last_event_id_(std::nullopt),
80
90
backoff_timer_(session_.get_executor()),
81
91
event_receiver_(std::move(receiver)),
@@ -347,6 +357,7 @@ Builder::Builder(net::any_io_executor ctx, std::string url)
347
357
read_timeout_{std::nullopt},
348
358
write_timeout_{std::nullopt},
349
359
connect_timeout_{std::nullopt},
360
+ initial_reconnect_delay_{std::nullopt},
350
361
logging_cb_ ([](auto msg) {}),
351
362
receiver_ ([](launchdarkly::sse::Event const &) {}),
352
363
error_cb_ ([](auto err) {}) {
@@ -382,6 +393,11 @@ Builder& Builder::write_timeout(std::chrono::milliseconds timeout) {
382
393
return *this ;
383
394
}
384
395
396
+ Builder& Builder::initial_reconnect_delay (std::chrono::milliseconds delay) {
397
+ initial_reconnect_delay_ = delay;
398
+ return *this ;
399
+ }
400
+
385
401
Builder& Builder::method (http::verb verb) {
386
402
request_.method (verb);
387
403
return *this ;
@@ -441,8 +457,8 @@ std::shared_ptr<Client> Builder::build() {
441
457
442
458
return std::make_shared<FoxyClient>(
443
459
net::make_strand (executor_), request, host, service, connect_timeout_,
444
- read_timeout_, write_timeout_, receiver_, logging_cb_, error_cb_ ,
445
- std::move (ssl));
460
+ read_timeout_, write_timeout_, initial_reconnect_delay_, receiver_ ,
461
+ logging_cb_, error_cb_, std::move (ssl));
446
462
}
447
463
448
464
} // namespace launchdarkly::sse
0 commit comments