Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-30 08:25:18

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_IMPL_INTERNAL_SANSIO_EXECUTE_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_EXECUTE_HPP
0010 
0011 #include <boost/mysql/diagnostics.hpp>
0012 #include <boost/mysql/error_code.hpp>
0013 
0014 #include <boost/mysql/detail/algo_params.hpp>
0015 #include <boost/mysql/detail/any_execution_request.hpp>
0016 #include <boost/mysql/detail/execution_processor/execution_processor.hpp>
0017 
0018 #include <boost/mysql/impl/internal/coroutine.hpp>
0019 #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
0020 #include <boost/mysql/impl/internal/sansio/read_resultset_head.hpp>
0021 #include <boost/mysql/impl/internal/sansio/read_some_rows.hpp>
0022 #include <boost/mysql/impl/internal/sansio/start_execution.hpp>
0023 
0024 namespace boost {
0025 namespace mysql {
0026 namespace detail {
0027 
0028 class read_execute_response_algo
0029 {
0030     int resume_point_{0};
0031     read_resultset_head_algo read_head_st_;
0032     read_some_rows_algo read_some_rows_st_;
0033 
0034 public:
0035     // We pass false because they are subordinate algos. This suppresses state checks.
0036     // This is always a subordinate algo, so it never performs state checks.
0037     read_execute_response_algo(execution_processor* proc) noexcept
0038         : read_head_st_({proc}, false), read_some_rows_st_({proc, output_ref()}, false)
0039     {
0040     }
0041 
0042     execution_processor& processor() { return read_head_st_.processor(); }
0043 
0044     next_action resume(connection_state_data& st, diagnostics& diag, error_code ec)
0045     {
0046         next_action act;
0047 
0048         switch (resume_point_)
0049         {
0050         case 0:
0051 
0052             while (!processor().is_complete())
0053             {
0054                 if (processor().is_reading_head())
0055                 {
0056                     read_head_st_.reset();
0057                     while (!(act = read_head_st_.resume(st, diag, ec)).is_done())
0058                         BOOST_MYSQL_YIELD(resume_point_, 1, act)
0059                     if (act.error())
0060                         return act;
0061                 }
0062                 else if (processor().is_reading_rows())
0063                 {
0064                     read_some_rows_st_.reset();
0065                     while (!(act = read_some_rows_st_.resume(st, diag, ec)).is_done())
0066                         BOOST_MYSQL_YIELD(resume_point_, 2, act)
0067                     if (act.error())
0068                         return act;
0069                 }
0070             }
0071         }
0072 
0073         return next_action();
0074     }
0075 };
0076 
0077 class execute_algo
0078 {
0079     int resume_point_{0};
0080     start_execution_algo start_execution_st_;
0081     read_execute_response_algo read_response_st_;
0082 
0083     execution_processor& processor() { return read_response_st_.processor(); }
0084 
0085 public:
0086     // We pass false to the start execution algo's constructor because it's a subordinate algo.
0087     // This disables state checks.
0088     execute_algo(execute_algo_params params) noexcept
0089         : start_execution_st_({params.req, params.proc}, false), read_response_st_(params.proc)
0090     {
0091     }
0092 
0093     next_action resume(connection_state_data& st, diagnostics& diag, error_code ec)
0094     {
0095         next_action act;
0096 
0097         switch (resume_point_)
0098         {
0099         case 0:
0100 
0101             // Check status
0102             ec = st.check_status_ready();
0103             if (ec)
0104                 return ec;
0105 
0106             // Send request and read the first response
0107             while (!(act = start_execution_st_.resume(st, diag, ec)).is_done())
0108                 BOOST_MYSQL_YIELD(resume_point_, 1, act)
0109             if (act.error())
0110                 return act;
0111 
0112             // Read anything else
0113             while (!(act = read_response_st_.resume(st, diag, ec)).is_done())
0114                 BOOST_MYSQL_YIELD(resume_point_, 2, act)
0115             return act;
0116         }
0117 
0118         return next_action();
0119     }
0120 };
0121 
0122 }  // namespace detail
0123 }  // namespace mysql
0124 }  // namespace boost
0125 
0126 #endif