|
22 | 22 | #include <limits>
|
23 | 23 |
|
24 | 24 | 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 |
61 | 25 |
|
62 | 26 | /** @brief A SSL connection to the Redis server.
|
63 | 27 | * @ingroup high-level-api
|
@@ -100,7 +64,6 @@ class basic_connection {
|
100 | 64 | asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client},
|
101 | 65 | std::size_t max_read_size = (std::numeric_limits<std::size_t>::max)())
|
102 | 66 | : impl_{ex, std::move(ctx), max_read_size}
|
103 |
| - , timer_{ex} |
104 | 67 | { }
|
105 | 68 |
|
106 | 69 | /// Contructs from a context.
|
@@ -158,14 +121,7 @@ class basic_connection {
|
158 | 121 | Logger l = Logger{},
|
159 | 122 | CompletionToken token = CompletionToken{})
|
160 | 123 | {
|
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)); |
169 | 125 | }
|
170 | 126 |
|
171 | 127 | /** @brief Receives server side pushes asynchronously.
|
@@ -287,22 +243,11 @@ class basic_connection {
|
287 | 243 | * @param op: The operation to be cancelled.
|
288 | 244 | */
|
289 | 245 | 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); } |
302 | 247 |
|
303 | 248 | /// Returns true if the connection was canceled.
|
304 | 249 | bool will_reconnect() const noexcept
|
305 |
| - { return cfg_.reconnect_wait_interval != std::chrono::seconds::zero();} |
| 250 | + { return impl_.will_reconnect();} |
306 | 251 |
|
307 | 252 | /// Returns the ssl context.
|
308 | 253 | auto const& get_ssl_context() const noexcept
|
@@ -330,17 +275,7 @@ class basic_connection {
|
330 | 275 | { return impl_.get_usage(); }
|
331 | 276 |
|
332 | 277 | 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_; |
342 | 278 | detail::connection_base<executor_type> impl_;
|
343 |
| - timer_type timer_; |
344 | 279 | };
|
345 | 280 |
|
346 | 281 | /** \brief A basic_connection that type erases the executor.
|
|
0 commit comments