Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:33:51

0001 //
0002 // Copyright (c) 2019-2024 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     read_execute_response_algo(diagnostics* diag, execution_processor* proc) noexcept
0036         : read_head_st_(read_resultset_head_algo_params{diag, proc}),
0037           read_some_rows_st_(read_some_rows_algo_params{diag, proc, output_ref()})
0038     {
0039     }
0040 
0041     diagnostics& diag() { return read_head_st_.diag(); }
0042     execution_processor& processor() { return read_head_st_.processor(); }
0043 
0044     next_action resume(connection_state_data& st, 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, 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, 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     diagnostics& diag() { return read_response_st_.diag(); }
0084     execution_processor& processor() { return read_response_st_.processor(); }
0085 
0086 public:
0087     execute_algo(execute_algo_params params) noexcept
0088         : start_execution_st_(start_execution_algo_params{params.diag, params.req, params.proc}),
0089           read_response_st_(params.diag, params.proc)
0090     {
0091     }
0092 
0093     next_action resume(connection_state_data& st, error_code ec)
0094     {
0095         next_action act;
0096 
0097         switch (resume_point_)
0098         {
0099         case 0:
0100 
0101             // Send request and read the first response
0102             while (!(act = start_execution_st_.resume(st, ec)).is_done())
0103                 BOOST_MYSQL_YIELD(resume_point_, 1, act)
0104             if (act.error())
0105                 return act;
0106 
0107             // Read anything else
0108             while (!(act = read_response_st_.resume(st, ec)).is_done())
0109                 BOOST_MYSQL_YIELD(resume_point_, 2, act)
0110             return act;
0111         }
0112 
0113         return next_action();
0114     }
0115 };
0116 
0117 }  // namespace detail
0118 }  // namespace mysql
0119 }  // namespace boost
0120 
0121 #endif