@@ -79,20 +79,22 @@ class FoxyClient : public Client,
79
79
read_timeout_(read_timeout),
80
80
write_timeout_(write_timeout),
81
81
req_(std::move(req)),
82
- backoff_(
83
- initial_reconnect_delay.value_or(kDefaultInitialReconnectDelay ),
84
- kDefaultMaxBackoffDelay),
85
- last_event_id_(std::nullopt),
86
- backoff_timer_(std::move(executor)),
87
82
event_receiver_(std::move(receiver)),
88
83
logger_(std::move(logger)),
89
84
errors_(std::move(errors)),
90
- last_read_(std::nullopt),
91
- shutting_down_(false ),
92
85
body_parser_(std::nullopt),
93
- session_(std::nullopt) {
86
+ session_(std::move(executor),
87
+ launchdarkly::foxy::session_opts{
88
+ ToOptRef (ssl_context_),
89
+ connect_timeout_.value_or (kNoTimeout )}),
90
+ last_event_id_ (std::nullopt),
91
+ backoff_(
92
+ initial_reconnect_delay.value_or(kDefaultInitialReconnectDelay ),
93
+ kDefaultMaxBackoffDelay),
94
+ backoff_timer_(session_.get_executor()),
95
+ last_read_(std::nullopt),
96
+ shutting_down_(false ) {
94
97
create_parser ();
95
- create_session ();
96
98
}
97
99
98
100
/* * Logs a message indicating that an async_read_some operation
@@ -132,13 +134,6 @@ class FoxyClient : public Client,
132
134
body_parser_->get ().body ().on_event (event_receiver_);
133
135
}
134
136
135
- void create_session () {
136
- session_.emplace (
137
- backoff_timer_.get_executor (),
138
- launchdarkly::foxy::session_opts{
139
- ToOptRef (ssl_context_), connect_timeout_.value_or (kNoTimeout )});
140
- }
141
-
142
137
/* *
143
138
* Called whenever the connection needs to be reattempted, triggering
144
139
* a timed wait for the current backoff duration.
@@ -165,7 +160,6 @@ class FoxyClient : public Client,
165
160
logger_ (msg.str ());
166
161
167
162
create_parser ();
168
- create_session ();
169
163
170
164
backoff_timer_.expires_from_now (backoff_.delay ());
171
165
backoff_timer_.async_wait (beast::bind_front_handler (
@@ -180,7 +174,7 @@ class FoxyClient : public Client,
180
174
}
181
175
182
176
void run () override {
183
- session_-> async_connect (
177
+ session_. async_connect (
184
178
host_, port_,
185
179
beast::bind_front_handler (&FoxyClient::on_connect,
186
180
shared_from_this ()));
@@ -199,10 +193,10 @@ class FoxyClient : public Client,
199
193
} else {
200
194
req_.erase (" last-event-id" );
201
195
}
202
- session_-> opts .timeout = write_timeout_.value_or (kNoTimeout );
203
- session_-> async_write (req_,
204
- beast::bind_front_handler (&FoxyClient::on_write,
205
- shared_from_this ()));
196
+ session_. opts .timeout = write_timeout_.value_or (kNoTimeout );
197
+ session_. async_write (req_,
198
+ beast::bind_front_handler (&FoxyClient::on_write,
199
+ shared_from_this ()));
206
200
}
207
201
208
202
void on_write (boost::system::error_code ec, std::size_t amount) {
@@ -214,8 +208,8 @@ class FoxyClient : public Client,
214
208
return do_backoff (ec.what ());
215
209
}
216
210
217
- session_-> opts .timeout = read_timeout_.value_or (kNoTimeout );
218
- session_-> async_read_header (
211
+ session_. opts .timeout = read_timeout_.value_or (kNoTimeout );
212
+ session_. async_read_header (
219
213
*body_parser_, beast::bind_front_handler (&FoxyClient::on_headers,
220
214
shared_from_this ()));
221
215
}
@@ -231,7 +225,7 @@ class FoxyClient : public Client,
231
225
232
226
if (!body_parser_->is_header_done ()) {
233
227
/* keep reading headers */
234
- return session_-> async_read_header (
228
+ return session_. async_read_header (
235
229
*body_parser_,
236
230
beast::bind_front_handler (&FoxyClient::on_headers,
237
231
shared_from_this ()));
@@ -253,7 +247,7 @@ class FoxyClient : public Client,
253
247
backoff_.succeed ();
254
248
255
249
last_read_ = std::chrono::steady_clock::now ();
256
- return session_-> async_read_some (
250
+ return session_. async_read_some (
257
251
*body_parser_,
258
252
beast::bind_front_handler (&FoxyClient::on_read_body,
259
253
shared_from_this ()));
@@ -311,7 +305,7 @@ class FoxyClient : public Client,
311
305
}
312
306
if (!ec) {
313
307
log_and_update_last_read (amount);
314
- return session_-> async_read_some (
308
+ return session_. async_read_some (
315
309
*body_parser_,
316
310
beast::bind_front_handler (&FoxyClient::on_read_body,
317
311
shared_from_this ()));
@@ -320,7 +314,7 @@ class FoxyClient : public Client,
320
314
}
321
315
322
316
void async_shutdown (std::function<void ()> completion) override {
323
- boost::asio::post (session_-> get_executor (),
317
+ boost::asio::post (session_. get_executor (),
324
318
beast::bind_front_handler (&FoxyClient::do_shutdown,
325
319
shared_from_this (),
326
320
std::move (completion)));
@@ -329,7 +323,7 @@ class FoxyClient : public Client,
329
323
void do_shutdown (std::function<void ()> completion) {
330
324
shutting_down_ = true ;
331
325
backoff_timer_.cancel ();
332
- session_-> async_shutdown (beast::bind_front_handler (
326
+ session_. async_shutdown (beast::bind_front_handler (
333
327
&FoxyClient::on_shutdown, std::move (completion)));
334
328
}
335
329
@@ -398,7 +392,7 @@ class FoxyClient : public Client,
398
392
Builder::ErrorCallback errors_;
399
393
400
394
std::optional<http::response_parser<body>> body_parser_;
401
- std::optional< launchdarkly::foxy::client_session> session_;
395
+ launchdarkly::foxy::client_session session_;
402
396
std::optional<std::string> last_event_id_;
403
397
Backoff backoff_;
404
398
boost::asio::steady_timer backoff_timer_;
0 commit comments