9#include <boost/asio.hpp>
10#if defined(BOOST_ASIO_HAS_CO_AWAIT)
11#include <boost/asio/experimental/awaitable_operators.hpp>
14namespace net = boost::asio;
15using namespace net::experimental::awaitable_operators;
16using resolver = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::resolver>;
17using timer_type = net::use_awaitable_t<>::as_default_on_t<net::steady_timer>;
24auto redir(boost::system::error_code& ec)
25 {
return net::redirect_error(net::use_awaitable, ec); }
28auto healthy_checker(std::shared_ptr<connection> conn) -> net::awaitable<void>
32 req.get_config().cancel_on_connection_lost =
true;
35 timer_type timer{
co_await net::this_coro::executor};
37 for (boost::system::error_code ec;;) {
38 timer.expires_after(std::chrono::seconds{1});
39 co_await (conn->async_exec(req,
adapt()) || timer.async_wait(redir(ec)));
46 timer.expires_after(std::chrono::seconds{1});
47 co_await timer.async_wait();
55 std::shared_ptr<connection> conn,
56 std::string
const& host,
57 std::string
const& port) -> net::awaitable<void>
59 auto ex =
co_await net::this_coro::executor;
63 boost::system::error_code ec;
64 timer.expires_after(std::chrono::seconds{5});
65 auto const addrs =
co_await (resv.async_resolve(host, port) || timer.async_wait(redir(ec)));
67 throw std::runtime_error(
"Resolve timeout");
69 timer.expires_after(std::chrono::seconds{5});
70 co_await (net::async_connect(conn->next_layer(), std::get<0>(addrs)) || timer.async_wait(redir(ec)));
72 throw std::runtime_error(
"Connect timeout");
auto adapt(std::size_t max_read_size=(std::numeric_limits< std::size_t >::max)()) noexcept
Creates an adapter that ignores responses.
operation
Connection operations that can be cancelled.