Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 09:00:18

0001 //
0002 // Copyright (c) 2025 Marcelo Zimbres Silva (mzimbres@gmail.com),
0003 // Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 
0009 #ifndef BOOST_REDIS_EXEC_FSM_HPP
0010 #define BOOST_REDIS_EXEC_FSM_HPP
0011 
0012 #include <boost/redis/detail/multiplexer.hpp>
0013 
0014 #include <boost/asio/cancellation_type.hpp>
0015 #include <boost/system/error_code.hpp>
0016 
0017 #include <cstddef>
0018 #include <memory>
0019 
0020 // Sans-io algorithm for async_exec, as a finite state machine
0021 
0022 namespace boost::redis::detail {
0023 
0024 // What should we do next?
0025 enum class exec_action_type
0026 {
0027    setup_cancellation,  // Set up the cancellation types supported by the composed operation
0028    immediate,           // Invoke asio::async_immediate to avoid re-entrancy problems
0029    done,                // Call the final handler
0030    notify_writer,       // Notify the writer task
0031    wait_for_response,   // Wait to be notified
0032 };
0033 
0034 class exec_action {
0035    exec_action_type type_;
0036    system::error_code ec_;
0037    std::size_t bytes_read_;
0038 
0039 public:
0040    exec_action(exec_action_type type) noexcept
0041    : type_{type}
0042    { }
0043 
0044    exec_action(system::error_code ec, std::size_t bytes_read = 0u) noexcept
0045    : type_{exec_action_type::done}
0046    , ec_{ec}
0047    , bytes_read_{bytes_read}
0048    { }
0049 
0050    exec_action_type type() const { return type_; }
0051    system::error_code error() const { return ec_; }
0052    std::size_t bytes_read() const { return bytes_read_; }
0053 };
0054 
0055 class exec_fsm {
0056    int resume_point_{0};
0057    multiplexer* mpx_{nullptr};
0058    std::shared_ptr<multiplexer::elem> elem_;
0059 
0060 public:
0061    exec_fsm(multiplexer& mpx, std::shared_ptr<multiplexer::elem> elem) noexcept
0062    : mpx_(&mpx)
0063    , elem_(std::move(elem))
0064    { }
0065 
0066    exec_action resume(bool connection_is_open, asio::cancellation_type_t cancel_state);
0067 };
0068 
0069 }  // namespace boost::redis::detail
0070 
0071 #endif  // BOOST_REDIS_CONNECTOR_HPP