Back to home page

EIC code displayed by LXR

 
 

    


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

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_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     diagnostics* diag_;
0029     std::uint8_t sequence_number_{0};
0030 
0031 public:
0032     quit_connection_algo(quit_connection_algo_params params) noexcept : diag_(params.diag) {}
0033 
0034     diagnostics& diag() { return *diag_; }
0035 
0036     next_action resume(connection_state_data& st, error_code ec)
0037     {
0038         switch (resume_point_)
0039         {
0040         case 0:
0041 
0042             // Clear diagnostics
0043             diag_->clear();
0044 
0045             // Send quit message
0046             BOOST_MYSQL_YIELD(resume_point_, 1, st.write(quit_command(), sequence_number_))
0047 
0048             // Mark the session as finished, regardless of the write result
0049             st.is_connected = false;
0050 
0051             // If write resulted in an error, return
0052             if (ec)
0053                 return ec;
0054 
0055             // Shutdown SSL. MySQL doesn't always shut down SSL correctly, so we ignore this error.
0056             if (st.ssl == ssl_state::active)
0057             {
0058                 BOOST_MYSQL_YIELD(resume_point_, 2, next_action::ssl_shutdown())
0059                 st.ssl = ssl_state::torn_down;
0060             }
0061 
0062             // Done
0063         }
0064 
0065         return next_action();
0066     }
0067 };
0068 
0069 }  // namespace detail
0070 }  // namespace mysql
0071 }  // namespace boost
0072 
0073 #endif /* INCLUDE_BOOST_MYSQL_DETAIL_NETWORK_ALGORITHMS_QUIT_CONNECTION_HPP_ */