Skip to content

Commit 9de5025

Browse files
committed
Split notify_error() in two functions.
1 parent cf83cf7 commit 9de5025

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

include/boost/redis/detail/multiplexer.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct multiplexer {
4949
done_();
5050
}
5151

52-
auto notify_error(system::error_code ec) noexcept -> void;
52+
auto set_error(system::error_code const& ec) noexcept -> void;
5353

5454
[[nodiscard]]
5555
auto is_waiting() const noexcept
@@ -115,7 +115,9 @@ struct multiplexer {
115115
std::size_t read_size_;
116116
};
117117

118-
auto remove(std::shared_ptr<elem> const& ptr) -> bool;
118+
using elem_ptr_type = std::shared_ptr<elem>;
119+
120+
auto remove(elem_ptr_type const& ptr) -> bool;
119121

120122
[[nodiscard]]
121123
auto prepare_write() -> std::size_t;
@@ -129,7 +131,7 @@ struct multiplexer {
129131
[[nodiscard]]
130132
auto consume_next(system::error_code& ec) -> std::pair<tribool, std::size_t>;
131133

132-
auto add(std::shared_ptr<elem> const& ptr) -> void;
134+
auto add(elem_ptr_type const& ptr) -> void;
133135
auto reset() -> void;
134136

135137
[[nodiscard]]
@@ -203,7 +205,7 @@ struct multiplexer {
203205

204206
std::string read_buffer_;
205207
std::string write_buffer_;
206-
std::deque<std::shared_ptr<elem>> reqs_;
208+
std::deque<elem_ptr_type> reqs_;
207209
resp3::parser parser_{};
208210
bool on_push_ = false;
209211
bool cancel_run_called_ = false;
@@ -212,7 +214,7 @@ struct multiplexer {
212214
};
213215

214216
auto make_elem(request const& req, multiplexer::pipeline_adapter_type adapter)
215-
-> std::shared_ptr<multiplexer::elem>;
217+
-> multiplexer::elem_ptr_type;
216218

217219
} // namespace detail
218220
} // namespace boost::redis

include/boost/redis/impl/multiplexer.ipp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ multiplexer::elem::elem(request const& req, pipeline_adapter_type adapter)
2525
};
2626
}
2727

28-
auto multiplexer::elem::notify_error(system::error_code ec) noexcept -> void
28+
auto multiplexer::elem::set_error(system::error_code const& ec) noexcept -> void
2929
{
30-
if (!ec_) {
30+
if (!ec_)
3131
ec_ = ec;
32-
}
33-
34-
notify_done();
3532
}
3633

3734
auto multiplexer::elem::commit_response(std::size_t read_size) -> void
@@ -40,7 +37,7 @@ auto multiplexer::elem::commit_response(std::size_t read_size) -> void
4037
--remaining_responses_;
4138
}
4239

43-
bool multiplexer::remove(std::shared_ptr<elem> const& ptr)
40+
bool multiplexer::remove(elem_ptr_type const& ptr)
4441
{
4542
if (ptr->is_waiting()) {
4643
reqs_.erase(std::remove(std::begin(reqs_), std::end(reqs_), ptr));
@@ -68,7 +65,7 @@ std::size_t multiplexer::commit_write()
6865
return release_push_requests();
6966
}
7067

71-
void multiplexer::add(std::shared_ptr<elem> const& info)
68+
void multiplexer::add(elem_ptr_type const& info)
7269
{
7370
reqs_.push_back(info);
7471

@@ -118,7 +115,8 @@ std::pair<tribool, std::size_t> multiplexer::consume_next(system::error_code& ec
118115
return std::make_pair(std::nullopt, 0);
119116

120117
if (ec) {
121-
reqs_.front()->notify_error(ec);
118+
reqs_.front()->set_error(ec);
119+
reqs_.front()->notify_done();
122120
reqs_.pop_front();
123121
return std::make_pair(std::make_optional(true), 0);
124122
}
@@ -179,7 +177,8 @@ std::size_t multiplexer::cancel_waiting()
179177
auto const ret = std::distance(point, std::end(reqs_));
180178

181179
std::for_each(point, std::end(reqs_), [](auto const& ptr) {
182-
ptr->notify_error({asio::error::operation_aborted});
180+
ptr->set_error({asio::error::operation_aborted});
181+
ptr->notify_done();
183182
});
184183

185184
reqs_.erase(point, std::end(reqs_));
@@ -210,7 +209,8 @@ auto multiplexer::cancel_on_conn_lost() -> std::size_t
210209
auto const ret = std::distance(point, std::end(reqs_));
211210

212211
std::for_each(point, std::end(reqs_), [](auto const& ptr) {
213-
ptr->notify_error({asio::error::operation_aborted});
212+
ptr->set_error({asio::error::operation_aborted});
213+
ptr->notify_done();
214214
});
215215

216216
reqs_.erase(point, std::end(reqs_));
@@ -306,7 +306,7 @@ bool multiplexer::is_waiting_response() const noexcept
306306
bool multiplexer::is_writing() const noexcept { return !write_buffer_.empty(); }
307307

308308
auto make_elem(request const& req, multiplexer::pipeline_adapter_type adapter)
309-
-> std::shared_ptr<multiplexer::elem>
309+
-> multiplexer::elem_ptr_type
310310
{
311311
return std::make_shared<multiplexer::elem>(req, std::move(adapter));
312312
}

0 commit comments

Comments
 (0)