123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- //
- // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- #ifndef BOOST_MYSQL_IMPL_INTERNAL_SANSIO_EXECUTE_HPP
- #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_EXECUTE_HPP
- #include <boost/mysql/diagnostics.hpp>
- #include <boost/mysql/error_code.hpp>
- #include <boost/mysql/detail/algo_params.hpp>
- #include <boost/mysql/detail/any_execution_request.hpp>
- #include <boost/mysql/detail/execution_processor/execution_processor.hpp>
- #include <boost/mysql/impl/internal/coroutine.hpp>
- #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
- #include <boost/mysql/impl/internal/sansio/read_resultset_head.hpp>
- #include <boost/mysql/impl/internal/sansio/read_some_rows.hpp>
- #include <boost/mysql/impl/internal/sansio/start_execution.hpp>
- namespace boost {
- namespace mysql {
- namespace detail {
- class read_execute_response_algo
- {
- int resume_point_{0};
- read_resultset_head_algo read_head_st_;
- read_some_rows_algo read_some_rows_st_;
- public:
- read_execute_response_algo(diagnostics* diag, execution_processor* proc) noexcept
- : read_head_st_(read_resultset_head_algo_params{diag, proc}),
- read_some_rows_st_(read_some_rows_algo_params{diag, proc, output_ref()})
- {
- }
- diagnostics& diag() { return read_head_st_.diag(); }
- execution_processor& processor() { return read_head_st_.processor(); }
- next_action resume(connection_state_data& st, error_code ec)
- {
- next_action act;
- switch (resume_point_)
- {
- case 0:
- while (!processor().is_complete())
- {
- if (processor().is_reading_head())
- {
- read_head_st_.reset();
- while (!(act = read_head_st_.resume(st, ec)).is_done())
- BOOST_MYSQL_YIELD(resume_point_, 1, act)
- if (act.error())
- return act;
- }
- else if (processor().is_reading_rows())
- {
- read_some_rows_st_.reset();
- while (!(act = read_some_rows_st_.resume(st, ec)).is_done())
- BOOST_MYSQL_YIELD(resume_point_, 2, act)
- if (act.error())
- return act;
- }
- }
- }
- return next_action();
- }
- };
- class execute_algo
- {
- int resume_point_{0};
- start_execution_algo start_execution_st_;
- read_execute_response_algo read_response_st_;
- diagnostics& diag() { return read_response_st_.diag(); }
- execution_processor& processor() { return read_response_st_.processor(); }
- public:
- execute_algo(execute_algo_params params) noexcept
- : start_execution_st_(start_execution_algo_params{params.diag, params.req, params.proc}),
- read_response_st_(params.diag, params.proc)
- {
- }
- next_action resume(connection_state_data& st, error_code ec)
- {
- next_action act;
- switch (resume_point_)
- {
- case 0:
- // Send request and read the first response
- while (!(act = start_execution_st_.resume(st, ec)).is_done())
- BOOST_MYSQL_YIELD(resume_point_, 1, act)
- if (act.error())
- return act;
- // Read anything else
- while (!(act = read_response_st_.resume(st, ec)).is_done())
- BOOST_MYSQL_YIELD(resume_point_, 2, act)
- return act;
- }
- return next_action();
- }
- };
- } // namespace detail
- } // namespace mysql
- } // namespace boost
- #endif
|