Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:58:20

0001 //
0002 // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_DETAIL_NEXT_ACTION_HPP
0009 #define BOOST_MYSQL_DETAIL_NEXT_ACTION_HPP
0010 
0011 #include <boost/mysql/error_code.hpp>
0012 
0013 #include <boost/assert.hpp>
0014 #include <boost/core/span.hpp>
0015 
0016 #include <cstdint>
0017 
0018 namespace boost {
0019 namespace mysql {
0020 namespace detail {
0021 
0022 enum class next_action_type
0023 {
0024     none,
0025     write,
0026     read,
0027     ssl_handshake,
0028     ssl_shutdown,
0029     connect,
0030     close,
0031 };
0032 
0033 class next_action
0034 {
0035 public:
0036     struct read_args_t
0037     {
0038         span<std::uint8_t> buffer;
0039         bool use_ssl;
0040     };
0041 
0042     struct write_args_t
0043     {
0044         span<const std::uint8_t> buffer;
0045         bool use_ssl;
0046     };
0047 
0048     next_action(error_code ec = {}) noexcept : type_(next_action_type::none), data_(ec) {}
0049 
0050     // Type
0051     next_action_type type() const noexcept { return type_; }
0052     bool is_done() const noexcept { return type_ == next_action_type::none; }
0053     bool success() const noexcept { return is_done() && !data_.ec; }
0054 
0055     // Arguments
0056     error_code error() const noexcept
0057     {
0058         BOOST_ASSERT(is_done());
0059         return data_.ec;
0060     }
0061     const void* connect_endpoint() const noexcept { return data_.connect_endpoint; }
0062     read_args_t read_args() const noexcept
0063     {
0064         BOOST_ASSERT(type_ == next_action_type::read);
0065         return data_.read_args;
0066     }
0067     write_args_t write_args() const noexcept
0068     {
0069         BOOST_ASSERT(type_ == next_action_type::write);
0070         return data_.write_args;
0071     }
0072 
0073     static next_action connect(const void* endpoint) noexcept
0074     {
0075         return next_action(next_action_type::connect, endpoint);
0076     }
0077     static next_action read(read_args_t args) noexcept { return next_action(next_action_type::read, args); }
0078     static next_action write(write_args_t args) noexcept
0079     {
0080         return next_action(next_action_type::write, args);
0081     }
0082     static next_action ssl_handshake() noexcept
0083     {
0084         return next_action(next_action_type::ssl_handshake, data_t());
0085     }
0086     static next_action ssl_shutdown() noexcept
0087     {
0088         return next_action(next_action_type::ssl_shutdown, data_t());
0089     }
0090     static next_action close() noexcept { return next_action(next_action_type::close, data_t()); }
0091 
0092 private:
0093     next_action_type type_{next_action_type::none};
0094     union data_t
0095     {
0096         error_code ec;
0097         const void* connect_endpoint;
0098         read_args_t read_args;
0099         write_args_t write_args;
0100 
0101         data_t() noexcept : ec(error_code()) {}
0102         data_t(const void* endpoint) noexcept : connect_endpoint(endpoint) {}
0103         data_t(error_code ec) noexcept : ec(ec) {}
0104         data_t(read_args_t args) noexcept : read_args(args) {}
0105         data_t(write_args_t args) noexcept : write_args(args) {}
0106     } data_;
0107 
0108     next_action(next_action_type t, data_t data) noexcept : type_(t), data_(data) {}
0109 };
0110 
0111 }  // namespace detail
0112 }  // namespace mysql
0113 }  // namespace boost
0114 
0115 #endif