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_CONNECT_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_CONNECT_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/sansio/connection_state_data.hpp>
0019 #include <boost/mysql/impl/internal/sansio/handshake.hpp>
0020 
0021 namespace boost {
0022 namespace mysql {
0023 namespace detail {
0024 
0025 class connect_algo
0026 {
0027     int resume_point_{0};
0028     handshake_algo handshake_;
0029     error_code stored_ec_;
0030 
0031 public:
0032     connect_algo(connect_algo_params params) noexcept
0033         : handshake_({params.diag, params.hparams, params.secure_channel})
0034     {
0035     }
0036 
0037     next_action resume(connection_state_data& st, error_code ec)
0038     {
0039         next_action act;
0040 
0041         switch (resume_point_)
0042         {
0043         case 0:
0044 
0045             // Clear diagnostics
0046             handshake_.diag().clear();
0047 
0048             // Physical connect
0049             BOOST_MYSQL_YIELD(resume_point_, 1, next_action::connect())
0050             if (ec)
0051                 return ec;
0052 
0053             // Handshake
0054             while (!(act = handshake_.resume(st, ec)).is_done())
0055                 BOOST_MYSQL_YIELD(resume_point_, 2, act)
0056 
0057             // If handshake failed, close the stream ignoring the result
0058             // and return handshake's error code
0059             if (act.error())
0060             {
0061                 stored_ec_ = act.error();
0062                 BOOST_MYSQL_YIELD(resume_point_, 3, next_action::close())
0063                 return stored_ec_;
0064             }
0065 
0066             // Done
0067         }
0068 
0069         return next_action();
0070     }
0071 };
0072 
0073 }  // namespace detail
0074 }  // namespace mysql
0075 }  // namespace boost
0076 
0077 #endif