Skip to content

Commit c615902

Browse files
committed
Simplifications
- Removes cancellation support from async_run. - Simplifies async operations. - Removes async_run_lean. - Remove support for implicit cancellation from health-checker. - Reuses async_run parallel group for health-checker tasks. - Moves the resolver from the runner to the connection. - Moves the connector from the runner to the connection_base class. - Moves the ssl handshaker to the connection_base class. - Moves the health-check to the connection_base class. - Simplifies cancel operations. - Improvements in logging. - Remove ssl handshaker. - Removes run_op from runner and renames runner to resp3_handshaker.
1 parent d910557 commit c615902

20 files changed

+489
-774
lines changed

include/boost/redis/connection.hpp

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,6 @@
2222
#include <limits>
2323

2424
namespace boost::redis {
25-
namespace detail
26-
{
27-
template <class Connection, class Logger>
28-
struct reconnection_op {
29-
Connection* conn_ = nullptr;
30-
Logger logger_;
31-
asio::coroutine coro_{};
32-
33-
template <class Self>
34-
void operator()(Self& self, system::error_code ec = {})
35-
{
36-
BOOST_ASIO_CORO_REENTER (coro_) for (;;)
37-
{
38-
BOOST_ASIO_CORO_YIELD
39-
conn_->impl_.async_run(conn_->cfg_, logger_, std::move(self));
40-
conn_->cancel(operation::receive);
41-
logger_.on_connection_lost(ec);
42-
if (!conn_->will_reconnect() || is_cancelled(self)) {
43-
conn_->cancel(operation::reconnection);
44-
self.complete(!!ec ? ec : asio::error::operation_aborted);
45-
return;
46-
}
47-
48-
conn_->timer_.expires_after(conn_->cfg_.reconnect_wait_interval);
49-
BOOST_ASIO_CORO_YIELD
50-
conn_->timer_.async_wait(std::move(self));
51-
BOOST_REDIS_CHECK_OP0(;)
52-
if (!conn_->will_reconnect()) {
53-
self.complete(asio::error::operation_aborted);
54-
return;
55-
}
56-
conn_->reset_stream();
57-
}
58-
}
59-
};
60-
} // detail
6125

6226
/** @brief A SSL connection to the Redis server.
6327
* @ingroup high-level-api
@@ -100,7 +64,6 @@ class basic_connection {
10064
asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client},
10165
std::size_t max_read_size = (std::numeric_limits<std::size_t>::max)())
10266
: impl_{ex, std::move(ctx), max_read_size}
103-
, timer_{ex}
10467
{ }
10568

10669
/// Contructs from a context.
@@ -158,14 +121,7 @@ class basic_connection {
158121
Logger l = Logger{},
159122
CompletionToken token = CompletionToken{})
160123
{
161-
using this_type = basic_connection<executor_type>;
162-
163-
cfg_ = cfg;
164-
l.set_prefix(cfg_.log_prefix);
165-
return asio::async_compose
166-
< CompletionToken
167-
, void(system::error_code)
168-
>(detail::reconnection_op<this_type, Logger>{this, l}, token, timer_);
124+
return impl_.async_run(cfg, l, std::move(token));
169125
}
170126

171127
/** @brief Receives server side pushes asynchronously.
@@ -287,22 +243,11 @@ class basic_connection {
287243
* @param op: The operation to be cancelled.
288244
*/
289245
void cancel(operation op = operation::all)
290-
{
291-
switch (op) {
292-
case operation::reconnection:
293-
case operation::all:
294-
cfg_.reconnect_wait_interval = std::chrono::seconds::zero();
295-
timer_.cancel();
296-
break;
297-
default: /* ignore */;
298-
}
299-
300-
impl_.cancel(op);
301-
}
246+
{ impl_.cancel(op); }
302247

303248
/// Returns true if the connection was canceled.
304249
bool will_reconnect() const noexcept
305-
{ return cfg_.reconnect_wait_interval != std::chrono::seconds::zero();}
250+
{ return impl_.will_reconnect();}
306251

307252
/// Returns the ssl context.
308253
auto const& get_ssl_context() const noexcept
@@ -330,17 +275,7 @@ class basic_connection {
330275
{ return impl_.get_usage(); }
331276

332277
private:
333-
using timer_type =
334-
asio::basic_waitable_timer<
335-
std::chrono::steady_clock,
336-
asio::wait_traits<std::chrono::steady_clock>,
337-
Executor>;
338-
339-
template <class, class> friend struct detail::reconnection_op;
340-
341-
config cfg_;
342278
detail::connection_base<executor_type> impl_;
343-
timer_type timer_;
344279
};
345280

346281
/** \brief A basic_connection that type erases the executor.

0 commit comments

Comments
 (0)