20
20
#include < boost/system.hpp>
21
21
#include < boost/asio/basic_stream_socket.hpp>
22
22
#include < boost/asio/bind_executor.hpp>
23
- #include < boost/asio/experimental/channel.hpp>
24
23
#include < boost/asio/experimental/parallel_group.hpp>
25
24
#include < boost/asio/ip/tcp.hpp>
26
25
#include < boost/asio/steady_timer.hpp>
@@ -52,10 +51,10 @@ struct wait_receive_op {
52
51
{
53
52
BOOST_ASIO_CORO_REENTER (coro)
54
53
{
55
- conn_->channel_ .cancel ();
54
+ conn_->read_op_timer_ .cancel ();
56
55
57
56
BOOST_ASIO_CORO_YIELD
58
- conn_->channel_ . async_send (system::error_code{}, 0 , std::move (self));
57
+ conn_->read_op_timer_ . async_wait ( std::move (self));
59
58
if (!conn_->is_open () || is_cancelled (self)) {
60
59
self.complete (!!ec ? ec : asio::error::operation_aborted);
61
60
return ;
@@ -143,7 +142,11 @@ class read_next_op {
143
142
144
143
++index_;
145
144
146
- BOOST_REDIS_CHECK_OP1 (conn_->cancel (operation::run););
145
+ if (ec || redis::detail::is_cancelled (self)) {
146
+ conn_->cancel (operation::run);
147
+ self.complete (!!ec ? ec : asio::error::operation_aborted, {});
148
+ return ;
149
+ }
147
150
148
151
read_size_ += n;
149
152
@@ -171,9 +174,9 @@ struct receive_op {
171
174
{
172
175
BOOST_ASIO_CORO_REENTER (coro)
173
176
{
174
- if (conn_->wait_read_op_notification_ ) {
177
+ if (! conn_->is_next_push () ) {
175
178
BOOST_ASIO_CORO_YIELD
176
- conn_->channel_ . async_receive (std::move (self));
179
+ conn_->read_op_timer_ . async_wait (std::move (self));
177
180
if (!conn_->is_open () || is_cancelled (self)) {
178
181
self.complete (!!ec ? ec : asio::error::operation_aborted, 0 );
179
182
return ;
@@ -194,9 +197,9 @@ struct receive_op {
194
197
195
198
read_size = n;
196
199
197
- conn_-> wait_read_op_notification_ = !conn_->is_next_maybe_push ();
198
- if ( conn_->wait_read_op_notification_ )
199
- conn_-> channel_ . cancel ();
200
+ if ( !conn_->is_next_push ()) {
201
+ conn_->read_op_timer_ . cancel ();
202
+ }
200
203
201
204
self.complete ({}, read_size);
202
205
return ;
@@ -320,7 +323,6 @@ struct run_op {
320
323
{
321
324
conn->write_buffer_ .clear ();
322
325
conn->read_buffer_ .clear ();
323
- conn->wait_read_op_notification_ = true ;
324
326
325
327
BOOST_ASIO_CORO_YIELD
326
328
asio::experimental::make_parallel_group (
@@ -496,11 +498,12 @@ class connection_base {
496
498
, stream_{std::make_unique<next_layer_type>(ex, ctx_)}
497
499
, writer_timer_{ex}
498
500
, read_timer_{ex}
499
- , channel_ {ex}
501
+ , read_op_timer_ {ex}
500
502
, runner_{ex, {}}
501
503
{
502
504
writer_timer_.expires_at (std::chrono::steady_clock::time_point::max ());
503
505
read_timer_.expires_at (std::chrono::steady_clock::time_point::max ());
506
+ read_op_timer_.expires_at (std::chrono::steady_clock::time_point::max ());
504
507
}
505
508
506
509
// / Contructs from an execution context.
@@ -628,7 +631,7 @@ class connection_base {
628
631
return asio::async_compose
629
632
< CompletionToken
630
633
, void (system::error_code, std::size_t )
631
- >(redis::detail::receive_op<this_type, decltype (f)>{this , f}, token, channel_ );
634
+ >(redis::detail::receive_op<this_type, decltype (f)>{this , f}, token, read_op_timer_ );
632
635
}
633
636
634
637
/* * @brief Starts underlying connection operations.
@@ -695,7 +698,6 @@ class connection_base {
695
698
using clock_type = std::chrono::steady_clock;
696
699
using clock_traits_type = asio::wait_traits<clock_type>;
697
700
using timer_type = asio::basic_waitable_timer<clock_type, clock_traits_type, executor_type>;
698
- using channel_type = asio::experimental::channel<executor_type, void (system::error_code, std::size_t )>;
699
701
using runner_type = redis::detail::runner<executor_type>;
700
702
701
703
auto use_ssl () const noexcept
@@ -767,7 +769,7 @@ class connection_base {
767
769
} break ;
768
770
case operation::receive:
769
771
{
770
- channel_ .cancel ();
772
+ read_op_timer_ .cancel ();
771
773
} break ;
772
774
default : /* ignore */ ;
773
775
}
@@ -891,7 +893,7 @@ class connection_base {
891
893
return asio::async_compose
892
894
< CompletionToken
893
895
, void (system::error_code)
894
- >(redis::detail::wait_receive_op<this_type>{this }, token, channel_ );
896
+ >(redis::detail::wait_receive_op<this_type>{this }, token, read_op_timer_ );
895
897
}
896
898
897
899
void cancel_push_requests ()
@@ -997,7 +999,7 @@ class connection_base {
997
999
stream_->next_layer ().close ();
998
1000
}
999
1001
1000
- bool is_next_maybe_push () const noexcept
1002
+ bool is_next_push () const noexcept
1001
1003
{
1002
1004
return !read_buffer_.empty () && (resp3::to_type (read_buffer_.front ()) == resp3::type::push);
1003
1005
}
@@ -1013,16 +1015,13 @@ class connection_base {
1013
1015
// not suspend.
1014
1016
timer_type writer_timer_;
1015
1017
timer_type read_timer_;
1016
- channel_type channel_ ;
1018
+ timer_type read_op_timer_ ;
1017
1019
runner_type runner_;
1018
1020
1019
1021
std::string read_buffer_;
1020
1022
std::string write_buffer_;
1021
1023
reqs_type reqs_;
1022
1024
std::size_t max_read_size_ = (std::numeric_limits<std::size_t >::max)();
1023
-
1024
- // Flag that optimizes reading pushes.
1025
- bool wait_read_op_notification_ = true ;
1026
1025
};
1027
1026
1028
1027
} // boost::redis
0 commit comments