1717#include < boost/asio/consign.hpp>
1818#include < boost/asio/coroutine.hpp>
1919#include < boost/asio/post.hpp>
20- #include < boost/asio/experimental/parallel_group.hpp>
2120#include < memory>
2221#include < chrono>
2322
@@ -36,6 +35,14 @@ class ping_op {
3635 {
3736 BOOST_ASIO_CORO_REENTER (coro_) for (;;)
3837 {
38+ if (checker_->ping_interval_ == std::chrono::seconds::zero ()) {
39+ logger_.trace (" ping-op: timeout disabled. Exiting ..." );
40+ BOOST_ASIO_CORO_YIELD
41+ asio::post (std::move (self));
42+ self.complete ({});
43+ return ;
44+ }
45+
3946 if (checker_->checker_has_exited_ ) {
4047 logger_.trace (" ping_op: checker has exited. Exiting ..." );
4148 self.complete ({});
@@ -77,6 +84,14 @@ class check_timeout_op {
7784 {
7885 BOOST_ASIO_CORO_REENTER (coro_) for (;;)
7986 {
87+ if (checker_->ping_interval_ == std::chrono::seconds::zero ()) {
88+ logger_.trace (" check-timeout-op: timeout disabled. Exiting ..." );
89+ BOOST_ASIO_CORO_YIELD
90+ asio::post (std::move (self));
91+ self.complete ({});
92+ return ;
93+ }
94+
8095 checker_->wait_timer_ .expires_after (2 * checker_->ping_interval_ );
8196 BOOST_ASIO_CORO_YIELD
8297 checker_->wait_timer_ .async_wait (std::move (self));
@@ -108,51 +123,6 @@ class check_timeout_op {
108123 }
109124};
110125
111- template <class HealthChecker , class Connection , class Logger >
112- class check_health_op {
113- public:
114- HealthChecker* checker_ = nullptr ;
115- Connection* conn_ = nullptr ;
116- Logger logger_;
117- asio::coroutine coro_{};
118-
119- template <class Self >
120- void
121- operator ()(
122- Self& self,
123- std::array<std::size_t , 2 > order = {},
124- system::error_code ec1 = {},
125- system::error_code ec2 = {})
126- {
127- BOOST_ASIO_CORO_REENTER (coro_)
128- {
129- if (checker_->ping_interval_ == std::chrono::seconds::zero ()) {
130- logger_.trace (" check-health-op: timeout disabled." );
131- BOOST_ASIO_CORO_YIELD
132- asio::post (std::move (self));
133- self.complete ({});
134- return ;
135- }
136-
137- BOOST_ASIO_CORO_YIELD
138- asio::experimental::make_parallel_group (
139- [this ](auto token) { return checker_->async_ping (*conn_, logger_, token); },
140- [this ](auto token) { return checker_->async_check_timeout (*conn_, logger_, token);}
141- ).async_wait (
142- asio::experimental::wait_for_one (),
143- std::move (self));
144-
145- logger_.on_check_health (ec1, ec2);
146-
147- switch (order[0 ]) {
148- case 0 : self.complete (ec1); return ;
149- case 1 : self.complete (ec2); return ;
150- default : BOOST_ASSERT (false );
151- }
152- }
153- }
154- };
155-
156126template <class Executor >
157127class health_checker {
158128private:
@@ -177,24 +147,6 @@ class health_checker {
177147 ping_interval_ = cfg.health_check_interval ;
178148 }
179149
180- template <
181- class Connection ,
182- class Logger ,
183- class CompletionToken = asio::default_completion_token_t <Executor>
184- >
185- auto
186- async_check_health (
187- Connection& conn,
188- Logger l,
189- CompletionToken token = CompletionToken{})
190- {
191- checker_has_exited_ = false ;
192- return asio::async_compose
193- < CompletionToken
194- , void (system::error_code)
195- >(check_health_op<health_checker, Connection, Logger>{this , &conn, l}, token, conn);
196- }
197-
198150 std::size_t cancel (operation op)
199151 {
200152 switch (op) {
@@ -209,7 +161,6 @@ class health_checker {
209161 return 0 ;
210162 }
211163
212- private:
213164 template <class Connection , class Logger , class CompletionToken >
214165 auto async_ping (Connection& conn, Logger l, CompletionToken token)
215166 {
@@ -228,9 +179,10 @@ class health_checker {
228179 >(check_timeout_op<health_checker, Connection, Logger>{this , &conn, l}, token, conn, wait_timer_);
229180 }
230181
182+ private:
183+
231184 template <class , class , class > friend class ping_op ;
232185 template <class , class , class > friend class check_timeout_op ;
233- template <class , class , class > friend class check_health_op ;
234186
235187 timer_type ping_timer_;
236188 timer_type wait_timer_;
0 commit comments