Skip to content

Commit 17e83ba

Browse files
committed
debug commit; revert me
1 parent 1b857a7 commit 17e83ba

File tree

4 files changed

+76
-42
lines changed

4 files changed

+76
-42
lines changed

examples/hello-cpp-client/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ int main() {
6262
std::cout << "*** Feature flag '" << FEATURE_FLAG_KEY << "' is "
6363
<< (flag_value ? "true" : "false") << " for this user\n\n";
6464

65+
for (int i = 0; i < 5; i++) {
66+
auto user_key = "example-user-key-" + std::to_string(i);
67+
auto context2 =
68+
ContextBuilder().Kind("user", user_key).Name("Bob").Build();
69+
70+
std::cout << "identifying " << user_key << std::endl;
71+
auto fut = client.IdentifyAsync(context2);
72+
fut.wait();
73+
std::cout << "identified " << user_key << "!" << std::endl;
74+
75+
std::this_thread::sleep_for(std::chrono::seconds(5));
76+
}
77+
6578
return 0;
6679
}
6780

libs/client-sdk/src/client_impl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@ std::future<bool> ClientImpl::IdentifyAsync(Context context) {
150150

151151
void ClientImpl::RestartDataSource() {
152152
if (data_source_) {
153-
data_source_->ShutdownAsync(nullptr);
153+
auto then = std::chrono::steady_clock::now();
154+
data_source_->ShutdownAsync([then]() {
155+
std::cout << "Shutdown in "
156+
<< std::chrono::duration_cast<std::chrono::milliseconds>(
157+
std::chrono::steady_clock::now() - then)
158+
.count()
159+
<< "ms" << std::endl;
160+
});
154161
}
155162
data_source_ = data_source_factory_();
156163
data_source_->Start();

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ auto const kDefaultMaxBackoffDelay = std::chrono::seconds(30);
4949
// we or the server are misbehaving here. In any case, there is no need to wait
5050
// 5 minutes, we should give a couple seconds to receive a valid response or
5151
// else stop waiting.
52-
auto const kShutdownTimeout = std::chrono::seconds(5);
52+
auto const kShutdownTimeout = std::chrono::seconds(10);
5353

5454
static boost::optional<net::ssl::context&> ToOptRef(
5555
std::optional<net::ssl::context>& maybe_val) {
@@ -292,8 +292,10 @@ class FoxyClient : public Client,
292292
// if we're shutting down, so shutting_down_ is needed to
293293
// disambiguate.
294294
if (shutting_down_) {
295-
// End the chain of async operations.
296-
return;
295+
session_->opts.timeout = kShutdownTimeout;
296+
297+
return session_->async_shutdown(beast::bind_front_handler(
298+
&FoxyClient::on_shutdown, shared_from_this(), []() {}));
297299
}
298300
errors_(Error::ReadTimeout);
299301
return async_backoff(
@@ -337,6 +339,7 @@ class FoxyClient : public Client,
337339
}
338340

339341
void async_shutdown(std::function<void()> completion) override {
342+
std::cout << "shutdown requested, posting..\n";
340343
// Get on the session's executor, otherwise the code in the completion
341344
// handler could race.
342345
boost::asio::post(session_->get_executor(),
@@ -346,15 +349,14 @@ class FoxyClient : public Client,
346349
}
347350

348351
void do_shutdown(std::function<void()> completion) {
352+
std::cout << "shutdown request executing..\n";
349353
shutting_down_ = true;
350354
backoff_timer_.cancel();
351-
session_->opts.timeout = kShutdownTimeout;
352355
if (session_->stream.is_ssl()) {
353356
session_->stream.ssl().next_layer().cancel();
357+
} else {
358+
session_->stream.plain().cancel();
354359
}
355-
session_->async_shutdown(beast::bind_front_handler(
356-
&FoxyClient::on_shutdown, shared_from_this(),
357-
std::move(completion)));
358360
}
359361

360362
void on_shutdown(std::function<void()> completion,
Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//
2-
// Copyright (c) 2018-2019 Christian Mazakas (christian dot mazakas at gmail dot com)
2+
// Copyright (c) 2018-2019 Christian Mazakas (christian dot mazakas at gmail dot
3+
// com)
34
//
4-
// Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
5-
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
67
//
78
// Official repository: https://github.com/LeonineKing1199/foxy
89
//
@@ -11,39 +12,50 @@
1112
#define FOXY_IMPL_CLIENT_SESSION_ASYNC_SHUTDOWN_IMPL_HPP_
1213

1314
#include <foxy/client_session.hpp>
14-
15-
namespace launchdarkly::foxy
16-
{
15+
#include <iostream>
16+
namespace launchdarkly::foxy {
1717
template <class DynamicBuffer>
1818
template <class ShutdownHandler>
19-
auto
20-
basic_client_session<DynamicBuffer>::async_shutdown(ShutdownHandler&& handler) & ->
21-
typename boost::asio::async_result<std::decay_t<ShutdownHandler>,
22-
void(boost::system::error_code)>::return_type
23-
{
24-
return ::launchdarkly::foxy::detail::async_timer<void(boost::system::error_code)>(
25-
[self = this, coro = boost::asio::coroutine()](auto& cb, boost::system::error_code ec = {},
26-
std::size_t bytes_transferrred = 0) mutable {
27-
auto& s = *self;
28-
29-
BOOST_ASIO_CORO_REENTER(coro)
30-
{
31-
if (s.stream.is_ssl()) {
32-
BOOST_ASIO_CORO_YIELD s.stream.ssl().async_shutdown(std::move(cb));
33-
if (ec == boost::asio::ssl::error::stream_truncated) { ec = {}; }
34-
if (ec) { goto upcall; }
35-
}
36-
37-
s.stream.plain().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
38-
s.stream.plain().close(ec);
39-
40-
upcall:
41-
return cb.complete(ec);
42-
}
43-
},
44-
*this, std::forward<ShutdownHandler>(handler));
19+
auto basic_client_session<DynamicBuffer>::async_shutdown(
20+
ShutdownHandler&& handler) & ->
21+
typename boost::asio::async_result<
22+
std::decay_t<ShutdownHandler>,
23+
void(boost::system::error_code)>::return_type {
24+
return ::launchdarkly::foxy::detail::async_timer<void(
25+
boost::system::error_code)>(
26+
[self = this, coro = boost::asio::coroutine()](
27+
auto& cb, boost::system::error_code ec = {},
28+
std::size_t bytes_transferrred = 0) mutable {
29+
auto& s = *self;
30+
31+
BOOST_ASIO_CORO_REENTER(coro) {
32+
if (s.stream.is_ssl()) {
33+
std::cout << "-> ssl().async_shutdown()\n";
34+
BOOST_ASIO_CORO_YIELD s.stream.ssl().async_shutdown(
35+
std::move(cb));
36+
std::cout << "<- ssl().async_shutdown: " << ec.message()
37+
<< '\n';
38+
if (ec == boost::asio::ssl::error::stream_truncated) {
39+
ec = {};
40+
}
41+
if (ec) {
42+
goto upcall;
43+
}
44+
}
45+
46+
std::cout << "plain socket shutdown\n";
47+
s.stream.plain().shutdown(
48+
boost::asio::ip::tcp::socket::shutdown_both, ec);
49+
s.stream.plain().close(ec);
50+
51+
upcall:
52+
std::cout << "invoke completion handler\n";
53+
return cb.complete(ec);
54+
}
55+
},
56+
*this, std::forward<ShutdownHandler>(handler));
4557
}
4658

47-
} // namespace launchdarkly::foxy
59+
} // namespace launchdarkly::foxy
4860

49-
#endif // FOXY_IMPL_CLIENT_SESSION_ASYNC_SHUTDOWN_IMPL_HPP_
61+
#endif // FOXY_IMPL_CLIENT_SESSION_ASYNC_SHUTDOWN_IMPL_HPP_

0 commit comments

Comments
 (0)