Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:39:17

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_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     const void* server_address_;
0029     handshake_algo handshake_;
0030     error_code stored_ec_;
0031 
0032 public:
0033     connect_algo(connect_algo_params params) noexcept
0034         : server_address_(params.server_address), handshake_({params.hparams, params.secure_channel})
0035     {
0036     }
0037 
0038     next_action resume(connection_state_data& st, diagnostics& diag, error_code ec)
0039     {
0040         next_action act;
0041 
0042         switch (resume_point_)
0043         {
0044         case 0:
0045             // Handshake and connect wipe out state, so no state checks are performed.
0046 
0047             // Physical connect
0048             BOOST_MYSQL_YIELD(resume_point_, 1, next_action::connect(server_address_))
0049             if (ec)
0050                 return ec;
0051 
0052             // Handshake
0053             while (!(act = handshake_.resume(st, diag, ec)).is_done())
0054                 BOOST_MYSQL_YIELD(resume_point_, 2, act)
0055 
0056             // If handshake failed, close the stream ignoring the result
0057             // and return handshake's error code
0058             if (act.error())
0059             {
0060                 stored_ec_ = act.error();
0061                 BOOST_MYSQL_YIELD(resume_point_, 3, next_action::close())
0062                 return stored_ec_;
0063             }
0064 
0065             // Done
0066         }
0067 
0068         return next_action();
0069     }
0070 };
0071 
0072 }  // namespace detail
0073 }  // namespace mysql
0074 }  // namespace boost
0075 
0076 #endif