Skip to content

Commit 300acdc

Browse files
committed
revert session construction changes
1 parent 4f7dc9e commit 300acdc

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

libs/server-sent-events/src/client.cpp

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,22 @@ class FoxyClient : public Client,
7979
read_timeout_(read_timeout),
8080
write_timeout_(write_timeout),
8181
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)),
8782
event_receiver_(std::move(receiver)),
8883
logger_(std::move(logger)),
8984
errors_(std::move(errors)),
90-
last_read_(std::nullopt),
91-
shutting_down_(false),
9285
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) {
9497
create_parser();
95-
create_session();
9698
}
9799

98100
/** Logs a message indicating that an async_read_some operation
@@ -132,13 +134,6 @@ class FoxyClient : public Client,
132134
body_parser_->get().body().on_event(event_receiver_);
133135
}
134136

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-
142137
/**
143138
* Called whenever the connection needs to be reattempted, triggering
144139
* a timed wait for the current backoff duration.
@@ -165,7 +160,6 @@ class FoxyClient : public Client,
165160
logger_(msg.str());
166161

167162
create_parser();
168-
create_session();
169163

170164
backoff_timer_.expires_from_now(backoff_.delay());
171165
backoff_timer_.async_wait(beast::bind_front_handler(
@@ -180,7 +174,7 @@ class FoxyClient : public Client,
180174
}
181175

182176
void run() override {
183-
session_->async_connect(
177+
session_.async_connect(
184178
host_, port_,
185179
beast::bind_front_handler(&FoxyClient::on_connect,
186180
shared_from_this()));
@@ -199,10 +193,10 @@ class FoxyClient : public Client,
199193
} else {
200194
req_.erase("last-event-id");
201195
}
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()));
206200
}
207201

208202
void on_write(boost::system::error_code ec, std::size_t amount) {
@@ -214,8 +208,8 @@ class FoxyClient : public Client,
214208
return do_backoff(ec.what());
215209
}
216210

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(
219213
*body_parser_, beast::bind_front_handler(&FoxyClient::on_headers,
220214
shared_from_this()));
221215
}
@@ -231,7 +225,7 @@ class FoxyClient : public Client,
231225

232226
if (!body_parser_->is_header_done()) {
233227
/* keep reading headers */
234-
return session_->async_read_header(
228+
return session_.async_read_header(
235229
*body_parser_,
236230
beast::bind_front_handler(&FoxyClient::on_headers,
237231
shared_from_this()));
@@ -253,7 +247,7 @@ class FoxyClient : public Client,
253247
backoff_.succeed();
254248

255249
last_read_ = std::chrono::steady_clock::now();
256-
return session_->async_read_some(
250+
return session_.async_read_some(
257251
*body_parser_,
258252
beast::bind_front_handler(&FoxyClient::on_read_body,
259253
shared_from_this()));
@@ -311,7 +305,7 @@ class FoxyClient : public Client,
311305
}
312306
if (!ec) {
313307
log_and_update_last_read(amount);
314-
return session_->async_read_some(
308+
return session_.async_read_some(
315309
*body_parser_,
316310
beast::bind_front_handler(&FoxyClient::on_read_body,
317311
shared_from_this()));
@@ -320,7 +314,7 @@ class FoxyClient : public Client,
320314
}
321315

322316
void async_shutdown(std::function<void()> completion) override {
323-
boost::asio::post(session_->get_executor(),
317+
boost::asio::post(session_.get_executor(),
324318
beast::bind_front_handler(&FoxyClient::do_shutdown,
325319
shared_from_this(),
326320
std::move(completion)));
@@ -329,7 +323,7 @@ class FoxyClient : public Client,
329323
void do_shutdown(std::function<void()> completion) {
330324
shutting_down_ = true;
331325
backoff_timer_.cancel();
332-
session_->async_shutdown(beast::bind_front_handler(
326+
session_.async_shutdown(beast::bind_front_handler(
333327
&FoxyClient::on_shutdown, std::move(completion)));
334328
}
335329

@@ -398,7 +392,7 @@ class FoxyClient : public Client,
398392
Builder::ErrorCallback errors_;
399393

400394
std::optional<http::response_parser<body>> body_parser_;
401-
std::optional<launchdarkly::foxy::client_session> session_;
395+
launchdarkly::foxy::client_session session_;
402396
std::optional<std::string> last_event_id_;
403397
Backoff backoff_;
404398
boost::asio::steady_timer backoff_timer_;

0 commit comments

Comments
 (0)