-
Notifications
You must be signed in to change notification settings - Fork 41
Removes async_append_some #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,13 @@ | |
#define BOOST_REDIS_MULTIPLEXER_HPP | ||
|
||
#include <boost/redis/adapter/adapt.hpp> | ||
#include <boost/redis/adapter/any_adapter.hpp> | ||
#include <boost/redis/config.hpp> | ||
#include <boost/redis/operation.hpp> | ||
#include <boost/redis/detail/read_buffer.hpp> | ||
#include <boost/redis/resp3/node.hpp> | ||
#include <boost/redis/resp3/parser.hpp> | ||
#include <boost/redis/resp3/type.hpp> | ||
#include <boost/redis/usage.hpp> | ||
|
||
#include <boost/asio/experimental/channel.hpp> | ||
#include <boost/system.hpp> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid whole-lib includes |
||
|
||
#include <algorithm> | ||
#include <deque> | ||
|
@@ -32,7 +32,8 @@ namespace detail { | |
|
||
using tribool = std::optional<bool>; | ||
|
||
struct multiplexer { | ||
class multiplexer { | ||
public: | ||
using adapter_type = std::function<void(resp3::node_view const&, system::error_code&)>; | ||
using pipeline_adapter_type = std::function< | ||
void(std::size_t, resp3::node_view const&, system::error_code&)>; | ||
|
@@ -127,7 +128,8 @@ struct multiplexer { | |
// If the tribool contains no value more data is needed, otherwise | ||
// if the value is true the message consumed is a push. | ||
[[nodiscard]] | ||
auto consume_next(system::error_code& ec) -> std::pair<tribool, std::size_t>; | ||
auto consume_next(std::string_view data, system::error_code& ec) | ||
-> std::pair<tribool, std::size_t>; | ||
|
||
auto add(std::shared_ptr<elem> const& ptr) -> void; | ||
auto reset() -> void; | ||
|
@@ -156,18 +158,6 @@ struct multiplexer { | |
return std::string_view{write_buffer_}; | ||
} | ||
|
||
[[nodiscard]] | ||
auto get_read_buffer() noexcept -> std::string& | ||
{ | ||
return read_buffer_; | ||
} | ||
|
||
[[nodiscard]] | ||
auto get_read_buffer() const noexcept -> std::string const& | ||
{ | ||
return read_buffer_; | ||
} | ||
|
||
// TODO: Change signature to receive an adapter instead of a | ||
// response. | ||
template <class Response> | ||
|
@@ -191,17 +181,18 @@ struct multiplexer { | |
[[nodiscard]] | ||
auto is_waiting_response() const noexcept -> bool; | ||
|
||
[[nodiscard]] | ||
auto on_finish_parsing(bool is_push) -> std::size_t; | ||
void commit_usage(bool is_push, std::size_t size); | ||
|
||
[[nodiscard]] | ||
auto is_next_push() const noexcept -> bool; | ||
auto is_next_push(std::string_view data) const noexcept -> bool; | ||
|
||
// Releases the number of requests that have been released. | ||
[[nodiscard]] | ||
auto release_push_requests() -> std::size_t; | ||
|
||
std::string read_buffer_; | ||
[[nodiscard]] | ||
tribool consume_next_impl(std::string_view data, system::error_code& ec); | ||
|
||
std::string write_buffer_; | ||
std::deque<std::shared_ptr<elem>> reqs_; | ||
resp3::parser parser_{}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Copyright (c) 2018-2025 Marcelo Zimbres Silva ([email protected]) | ||
* | ||
* Distributed under the Boost Software License, Version 1.0. (See | ||
* accompanying file LICENSE.txt) | ||
*/ | ||
|
||
#ifndef BOOST_REDIS_READ_BUFFER_HPP | ||
#define BOOST_REDIS_READ_BUFFER_HPP | ||
|
||
#include <cstddef> | ||
#include <string> | ||
#include <string_view> | ||
#include <utility> | ||
|
||
namespace boost::redis::detail { | ||
|
||
class read_buffer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest adding a test_read_buffer unit test that covers these functions, even if they're small |
||
public: | ||
void prepare_append( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest returning the error code with [[nodiscard]] |
||
std::size_t append_size, | ||
std::size_t max_buffer_size, | ||
system::error_code& ec); | ||
|
||
void commit_append(std::size_t read_size); | ||
|
||
[[nodiscard]] | ||
auto get_append_buffer() noexcept -> std::pair<char*, std::size_t>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider replacing by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not public, so I avoided pulling in another boost dependency. |
||
|
||
[[nodiscard]] | ||
auto get_committed_buffer() const noexcept -> std::string_view; | ||
|
||
[[nodiscard]] | ||
auto get_committed_size() const noexcept -> std::size_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but it avoids creating a |
||
|
||
void clear(); | ||
|
||
void consume(std::size_t size); | ||
|
||
private: | ||
std::string buffer_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better represented as |
||
std::size_t append_buf_begin_ = 0; | ||
}; | ||
|
||
} // namespace boost::redis::detail | ||
|
||
#endif // BOOST_REDIS_READ_BUFFER_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,12 @@ namespace boost::redis::detail { | |
|
||
class reader_fsm { | ||
public: | ||
// See config.hpp for the meaning of these parameters. | ||
struct config { | ||
std::size_t read_buffer_append_size = 4096; | ||
std::size_t max_read_buffer_size = -1; | ||
}; | ||
|
||
struct action { | ||
enum class type | ||
{ | ||
|
@@ -41,8 +47,20 @@ class reader_fsm { | |
system::error_code ec, | ||
asio::cancellation_type_t /*cancel_state*/); | ||
|
||
void set_config(config const& cfg) noexcept { cfg_ = cfg; }; | ||
|
||
void reset(); | ||
|
||
[[nodiscard]] | ||
auto get_append_buffer() noexcept | ||
{ | ||
return read_buffer_.get_append_buffer(); | ||
} | ||
|
||
private: | ||
int resume_point_{0}; | ||
read_buffer read_buffer_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd make read_buffer_ a property of the connection, and pass here a pointer. This way, FSMs are kept non-owning. This way, you don't need reset(), and can just re-create the FSM every time, making it impossible to create bugs by forgetting members in reset(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, also considered this but did not go so far because I had change so much code already. |
||
config cfg_; | ||
action action_after_resume_; | ||
action::type next_read_type_ = action::type::append_some; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a needs_more action and a next_read_type_? It looks like it has the same semantics as append_some. append_some should likely be renamed to read_some There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs_more is useful in some situations
That is reasonable, I can change it. |
||
multiplexer* mpx_ = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As written, this yields to a dangling pointer after a connection is moved. I suggest wrapping every member in |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a braking change, is there a possibility to maintain the old name?