Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:52:42

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_QUIT_CONNECTION_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_QUIT_CONNECTION_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/next_action.hpp>
0016 
0017 #include <boost/mysql/impl/internal/coroutine.hpp>
0018 #include <boost/mysql/impl/internal/protocol/serialization.hpp>
0019 #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
0020 
0021 namespace boost {
0022 namespace mysql {
0023 namespace detail {
0024 
0025 class quit_connection_algo
0026 {
0027     int resume_point_{0};
0028     std::uint8_t sequence_number_{0};
0029     bool should_perform_shutdown_{};
0030 
0031 public:
0032     quit_connection_algo(quit_connection_algo_params) noexcept {}
0033 
0034     next_action resume(connection_state_data& st, diagnostics&, error_code ec)
0035     {
0036         switch (resume_point_)
0037         {
0038         case 0:
0039             // This can only be top-level in connection, and never in any_connection.
0040             // State checks are not worthy here - already handled by close.
0041 
0042             // Mark the session as finished
0043             should_perform_shutdown_ = st.tls_active;
0044             st.status = connection_status::not_connected;
0045             st.tls_active = false;
0046 
0047             // Send quit message
0048             BOOST_MYSQL_YIELD(resume_point_, 1, st.write(quit_command(), sequence_number_))
0049             if (ec)
0050                 return ec;
0051 
0052             // If there was no error and TLS is active, attempt TLS shutdown.
0053             // MySQL usually just closes the socket, instead of
0054             // sending the close_notify message required by the shutdown, so we ignore this error.
0055             if (should_perform_shutdown_)
0056             {
0057                 BOOST_MYSQL_YIELD(resume_point_, 2, next_action::ssl_shutdown())
0058             }
0059         }
0060 
0061         return next_action();
0062     }
0063 };
0064 
0065 }  // namespace detail
0066 }  // namespace mysql
0067 }  // namespace boost
0068 
0069 #endif /* INCLUDE_BOOST_MYSQL_DETAIL_NETWORK_ALGORITHMS_QUIT_CONNECTION_HPP_ */