Loading...
Searching...
No Matches
reader_fsm.hpp
1/* Copyright (c) 2018-2025 Marcelo Zimbres Silva (mzimbres@gmail.com)
2 *
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE.txt)
5 */
6
7#ifndef BOOST_REDIS_READER_FSM_HPP
8#define BOOST_REDIS_READER_FSM_HPP
9
10#include <boost/redis/detail/multiplexer.hpp>
11
12#include <boost/asio/cancellation_type.hpp>
13#include <boost/system/error_code.hpp>
14
15#include <cstddef>
16
17namespace boost::redis::detail {
18
19class reader_fsm {
20public:
21 struct action {
22 enum class type
23 {
24 setup_cancellation,
25 append_some,
26 needs_more,
27 notify_push_receiver,
28 cancel_run,
29 done,
30 };
31
32 type type_ = type::setup_cancellation;
33 std::size_t push_size_ = 0;
34 system::error_code ec_ = {};
35 };
36
37 explicit reader_fsm(multiplexer& mpx) noexcept;
38
39 action resume(
40 std::size_t bytes_read,
41 system::error_code ec,
42 asio::cancellation_type_t /*cancel_state*/);
43
44private:
45 int resume_point_{0};
46 action action_after_resume_;
47 action::type next_read_type_ = action::type::append_some;
48 multiplexer* mpx_ = nullptr;
49 std::pair<tribool, std::size_t> res_{std::make_pair(std::nullopt, 0)};
50};
51
52} // namespace boost::redis::detail
53
54#endif // BOOST_REDIS_READER_FSM_HPP