@@ -37,6 +37,9 @@ 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
+ auto const kDefaultInitialReconnectDelay = std::chrono::seconds(1 );
41
+ auto const kDefaultMaxReconnectDelay = std::chrono::seconds(30 );
42
+
40
43
static boost::optional<net::ssl::context&> ToOptRef (
41
44
std::optional<net::ssl::context>& maybe_val) {
42
45
if (maybe_val) {
@@ -60,6 +63,7 @@ class FoxyClient : public Client,
60
63
std::optional<std::chrono::milliseconds> connect_timeout,
61
64
std::optional<std::chrono::milliseconds> read_timeout,
62
65
std::optional<std::chrono::milliseconds> write_timeout,
66
+ std::optional<std::chrono::milliseconds> initial_reconnect_delay,
63
67
Builder::EventReceiver receiver,
64
68
Builder::LogCallback logger,
65
69
Builder::ErrorCallback errors,
@@ -75,7 +79,9 @@ class FoxyClient : public Client,
75
79
launchdarkly::foxy::session_opts{
76
80
ToOptRef (ssl_context_),
77
81
connect_timeout.value_or (kNoTimeout )}),
78
- backoff_ (std::chrono::seconds(1 ), std::chrono::seconds(30 )),
82
+ backoff_ (
83
+ initial_reconnect_delay.value_or(kDefaultInitialReconnectDelay ),
84
+ kDefaultMaxReconnectDelay),
79
85
last_event_id_(std::nullopt),
80
86
backoff_timer_(session_.get_executor()),
81
87
event_receiver_(std::move(receiver)),
@@ -347,6 +353,7 @@ Builder::Builder(net::any_io_executor ctx, std::string url)
347
353
read_timeout_{std::nullopt},
348
354
write_timeout_{std::nullopt},
349
355
connect_timeout_{std::nullopt},
356
+ initial_reconnect_delay_{std::nullopt},
350
357
logging_cb_ ([](auto msg) {}),
351
358
receiver_ ([](launchdarkly::sse::Event const &) {}),
352
359
error_cb_ ([](auto err) {}) {
@@ -382,6 +389,11 @@ Builder& Builder::write_timeout(std::chrono::milliseconds timeout) {
382
389
return *this ;
383
390
}
384
391
392
+ Builder& Builder::initial_reconnect_delay (std::chrono::milliseconds delay) {
393
+ initial_reconnect_delay_ = delay;
394
+ return *this ;
395
+ }
396
+
385
397
Builder& Builder::method (http::verb verb) {
386
398
request_.method (verb);
387
399
return *this ;
@@ -441,8 +453,8 @@ std::shared_ptr<Client> Builder::build() {
441
453
442
454
return std::make_shared<FoxyClient>(
443
455
net::make_strand (executor_), request, host, service, connect_timeout_,
444
- read_timeout_, write_timeout_, receiver_, logging_cb_, error_cb_ ,
445
- std::move (ssl));
456
+ read_timeout_, write_timeout_, initial_reconnect_delay_, receiver_ ,
457
+ logging_cb_, error_cb_, std::move (ssl));
446
458
}
447
459
448
460
} // namespace launchdarkly::sse
0 commit comments