Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 09:54:57

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_CLOSE_CONNECTION_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_CLOSE_CONNECTION_HPP
0010 
0011 #include <boost/mysql/diagnostics.hpp>
0012 
0013 #include <boost/mysql/detail/algo_params.hpp>
0014 #include <boost/mysql/detail/next_action.hpp>
0015 
0016 #include <boost/mysql/impl/internal/coroutine.hpp>
0017 #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
0018 #include <boost/mysql/impl/internal/sansio/quit_connection.hpp>
0019 
0020 namespace boost {
0021 namespace mysql {
0022 namespace detail {
0023 
0024 class close_connection_algo
0025 {
0026     int resume_point_{0};
0027     quit_connection_algo quit_{{}};
0028     error_code stored_ec_;
0029 
0030 public:
0031     close_connection_algo(close_connection_algo_params) noexcept {}
0032 
0033     next_action resume(connection_state_data& st, diagnostics& diag, error_code ec)
0034     {
0035         next_action act;
0036 
0037         switch (resume_point_)
0038         {
0039         case 0:
0040 
0041             // If we're not connected, we're done.
0042             // If we're in a multi-function operation, it's safe to proceed.
0043             if (st.status == connection_status::not_connected)
0044                 return next_action();
0045 
0046             // Attempt quit
0047             while (!(act = quit_.resume(st, diag, ec)).is_done())
0048                 BOOST_MYSQL_YIELD(resume_point_, 1, act)
0049             stored_ec_ = act.error();
0050 
0051             // Close the transport
0052             BOOST_MYSQL_YIELD(resume_point_, 2, next_action::close())
0053 
0054             // If quit resulted in an error, keep that error.
0055             // Otherwise, return any error derived from close
0056             if (stored_ec_)
0057                 ec = stored_ec_;
0058         }
0059 
0060         return ec;
0061     }
0062 };
0063 
0064 }  // namespace detail
0065 }  // namespace mysql
0066 }  // namespace boost
0067 
0068 #endif