|
21 | 21 | #include <limits> |
22 | 22 |
|
23 | 23 | namespace boost::redis { |
24 | | -namespace detail |
25 | | -{ |
26 | | -template <class Connection, class Logger> |
27 | | -struct reconnection_op { |
28 | | - Connection* conn_ = nullptr; |
29 | | - Logger logger_; |
30 | | - asio::coroutine coro_{}; |
31 | | - |
32 | | - template <class Self> |
33 | | - void operator()(Self& self, system::error_code ec = {}) |
34 | | - { |
35 | | - BOOST_ASIO_CORO_REENTER (coro_) for (;;) |
36 | | - { |
37 | | - BOOST_ASIO_CORO_YIELD |
38 | | - conn_->impl_.async_run(conn_->cfg_, logger_, std::move(self)); |
39 | | - conn_->cancel(operation::receive); |
40 | | - logger_.on_connection_lost(ec); |
41 | | - if (!conn_->will_reconnect()) { |
42 | | - conn_->cancel(operation::reconnection); |
43 | | - self.complete(ec); |
44 | | - return; |
45 | | - } |
46 | | - |
47 | | - conn_->timer_.expires_after(conn_->cfg_.reconnect_wait_interval); |
48 | | - BOOST_ASIO_CORO_YIELD |
49 | | - conn_->timer_.async_wait(std::move(self)); |
50 | | - BOOST_REDIS_CHECK_OP0(;) |
51 | | - if (!conn_->will_reconnect()) { |
52 | | - self.complete(asio::error::operation_aborted); |
53 | | - return; |
54 | | - } |
55 | | - |
56 | | - conn_->reset_stream(); |
57 | | - } |
58 | | - } |
59 | | -}; |
60 | | -} // detail |
61 | 24 |
|
62 | 25 | /** @brief A SSL connection to the Redis server. |
63 | 26 | * @ingroup high-level-api |
@@ -100,7 +63,6 @@ class basic_connection { |
100 | 63 | asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client}, |
101 | 64 | std::size_t max_read_size = (std::numeric_limits<std::size_t>::max)()) |
102 | 65 | : impl_{ex, std::move(ctx), max_read_size} |
103 | | - , timer_{ex} |
104 | 66 | { } |
105 | 67 |
|
106 | 68 | /// Contructs from a context. |
@@ -158,14 +120,7 @@ class basic_connection { |
158 | 120 | Logger l = Logger{}, |
159 | 121 | CompletionToken token = CompletionToken{}) |
160 | 122 | { |
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_); |
| 123 | + return impl_.async_run(cfg, l, std::move(token)); |
169 | 124 | } |
170 | 125 |
|
171 | 126 | /** @brief Receives server side pushes asynchronously. |
@@ -272,22 +227,11 @@ class basic_connection { |
272 | 227 | * @param op: The operation to be cancelled. |
273 | 228 | */ |
274 | 229 | void cancel(operation op = operation::all) |
275 | | - { |
276 | | - switch (op) { |
277 | | - case operation::reconnection: |
278 | | - case operation::all: |
279 | | - cfg_.reconnect_wait_interval = std::chrono::seconds::zero(); |
280 | | - timer_.cancel(); |
281 | | - break; |
282 | | - default: /* ignore */; |
283 | | - } |
284 | | - |
285 | | - impl_.cancel(op); |
286 | | - } |
| 230 | + { impl_.cancel(op); } |
287 | 231 |
|
288 | 232 | /// Returns true if the connection was canceled. |
289 | 233 | bool will_reconnect() const noexcept |
290 | | - { return cfg_.reconnect_wait_interval != std::chrono::seconds::zero();} |
| 234 | + { return impl_.will_reconnect();} |
291 | 235 |
|
292 | 236 | /// Returns the ssl context. |
293 | 237 | auto const& get_ssl_context() const noexcept |
@@ -315,17 +259,7 @@ class basic_connection { |
315 | 259 | { return impl_.get_usage(); } |
316 | 260 |
|
317 | 261 | private: |
318 | | - using timer_type = |
319 | | - asio::basic_waitable_timer< |
320 | | - std::chrono::steady_clock, |
321 | | - asio::wait_traits<std::chrono::steady_clock>, |
322 | | - Executor>; |
323 | | - |
324 | | - template <class, class> friend struct detail::reconnection_op; |
325 | | - |
326 | | - config cfg_; |
327 | 262 | detail::connection_base<executor_type> impl_; |
328 | | - timer_type timer_; |
329 | 263 | }; |
330 | 264 |
|
331 | 265 | /** \brief A basic_connection that type erases the executor. |
|
0 commit comments