Skip to content

Commit

Permalink
connect & new algo_runner
Browse files Browse the repository at this point in the history
  • Loading branch information
anarthal committed Oct 24, 2023
1 parent 9b5470e commit 87a3244
Show file tree
Hide file tree
Showing 20 changed files with 693 additions and 876 deletions.
52 changes: 18 additions & 34 deletions include/boost/mysql/detail/connection_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <boost/mysql/detail/config.hpp>
#include <boost/mysql/detail/execution_processor/execution_processor.hpp>
#include <boost/mysql/detail/execution_processor/execution_state_impl.hpp>
#include <boost/mysql/detail/generic_algo.hpp>
#include <boost/mysql/detail/network_algorithm_traits.hpp>
#include <boost/mysql/detail/run_algo.hpp>
#include <boost/mysql/detail/typing/get_type_index.hpp>
#include <boost/mysql/detail/writable_field_traits.hpp>

Expand Down Expand Up @@ -121,37 +121,16 @@ class connection_impl
BOOST_MYSQL_DECL
static std::vector<field_view>& get_shared_fields(connection_state& st) noexcept;

// Utilities for standard network algorithms
struct generic_initiation
// Generic algorithm
struct run_algo_initiation
{
template <class Handler, class OpParams, class... Args>
void operator()(Handler&& handler, any_stream* stream, connection_state* st, OpParams params)
{
async_generic_algo(*stream, *st, params, std::forward<Handler>(handler));
async_run_algo(*stream, *st, params, std::forward<Handler>(handler));
}
};

// connect
BOOST_MYSQL_DECL
static void connect_erased(
any_stream& stream,
connection_state& st,
const void* endpoint,
const handshake_params& params,
error_code& err,
diagnostics& diag
);

BOOST_MYSQL_DECL
static void async_connect_erased(
any_stream& stream,
connection_state& st,
const void* endpoint,
const handshake_params& params,
diagnostics& diag,
any_void_handler handler
);

template <class Stream>
struct connect_initiation
{
Expand All @@ -165,7 +144,12 @@ class connection_impl
diagnostics* diag
)
{
async_connect_erased(*stream, *st, &endpoint, params, *diag, std::forward<Handler>(handler));
async_run_algo(
*stream,
*st,
connect_op_params{&endpoint, diag, params, stream->supports_ssl()},
std::forward<Handler>(handler)
);
}
};

Expand All @@ -183,7 +167,7 @@ class connection_impl
)
{
auto getter = make_request_getter(req, get_shared_fields(*st));
async_generic_algo(
async_run_algo(
*stream,
*st,
execute_op_params{diag, getter.get(), proc},
Expand All @@ -206,7 +190,7 @@ class connection_impl
)
{
auto getter = make_request_getter(req, get_shared_fields(*st));
async_generic_algo(
async_run_algo(
*stream,
*st,
start_execution_op_params{diag, getter.get(), proc},
Expand Down Expand Up @@ -245,7 +229,7 @@ class connection_impl
async_generic_algo_iface(OpParams params, CompletionToken&& token)
{
return asio::async_initiate<CompletionToken, completion_signature_t<OpParams>>(
generic_initiation(),
run_algo_initiation(),
token,
stream_.get(),
st_.get(),
Expand All @@ -256,7 +240,7 @@ class connection_impl
template <class OpParams>
typename OpParams::result_type generic_algo_iface(OpParams params, error_code& ec)
{
return generic_algo(*stream_, *st_, params, ec);
return run_algo(*stream_, *st_, params, ec);
}

// Connect. This handles casting to the corresponding endpoint_type, if required
Expand All @@ -268,7 +252,7 @@ class connection_impl
diagnostics& diag
)
{
connect_erased(*stream_, *st_, &ep, params, err, diag);
run_algo(*stream_, *st_, connect_op_params{&ep, &diag, params, stream_->supports_ssl()}, err);
}

template <class Stream, class CompletionToken>
Expand Down Expand Up @@ -303,7 +287,7 @@ class connection_impl
void execute(const ExecutionRequest& req, ResultsType& result, error_code& err, diagnostics& diag)
{
auto getter = make_request_getter(req, get_shared_fields(*st_));
generic_algo(
run_algo(
*stream_,
*st_,
execute_op_params{&diag, getter.get(), &access::get_impl(result).get_interface()},
Expand Down Expand Up @@ -336,7 +320,7 @@ class connection_impl
)
{
auto getter = make_request_getter(req, get_shared_fields(*st_));
generic_algo(
run_algo(
*stream_,
*st_,
start_execution_op_params{&diag, getter.get(), &access::get_impl(exec_st).get_interface()},
Expand Down Expand Up @@ -423,7 +407,7 @@ class connection_impl
} // namespace boost

#ifdef BOOST_MYSQL_HEADER_ONLY
#include <boost/mysql/impl/channel_ptr.ipp>
#include <boost/mysql/impl/connection_impl.ipp>
#endif

#endif
10 changes: 10 additions & 0 deletions include/boost/mysql/detail/network_algorithm_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ namespace boost {
namespace mysql {
namespace detail {

struct connect_op_params
{
const void* connect_arg;
diagnostics* diag;
handshake_params hparams;
bool transport_supports_ssl;

using result_type = void;
};

struct handshake_op_params
{
diagnostics* diag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef BOOST_MYSQL_DETAIL_GENERIC_ALGO_HPP
#define BOOST_MYSQL_DETAIL_GENERIC_ALGO_HPP
#ifndef BOOST_MYSQL_DETAIL_RUN_ALGO_HPP
#define BOOST_MYSQL_DETAIL_RUN_ALGO_HPP

#include <boost/mysql/error_code.hpp>

Expand Down Expand Up @@ -47,15 +47,15 @@ template <class OpParams>
using completion_handler_t = asio::any_completion_handler<completion_signature_t<OpParams>>;

template <class OpParams>
typename OpParams::result_type generic_algo(
typename OpParams::result_type run_algo(
any_stream& stream,
connection_state& st,
OpParams params,
error_code& ec
);

template <class OpParams>
void async_generic_algo(
void async_run_algo(
any_stream& stream,
connection_state& st,
OpParams params,
Expand All @@ -67,7 +67,7 @@ void async_generic_algo(
} // namespace boost

#ifdef BOOST_MYSQL_HEADER_ONLY
#include <boost/mysql/impl/generic_algo.ipp>
#include <boost/mysql/impl/run_algo.ipp>
#endif

#endif
27 changes: 0 additions & 27 deletions include/boost/mysql/impl/connection_impl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,17 @@
#include <boost/mysql/detail/any_stream.hpp>
#include <boost/mysql/detail/connection_impl.hpp>

#include <boost/mysql/impl/internal/network_algorithms/connect.hpp>
#include <boost/mysql/impl/internal/sansio/connection_state.hpp>

#include <memory>

// Misc
std::vector<boost::mysql::field_view>& boost::mysql::detail::connection_impl::get_shared_fields(
connection_state& st
) noexcept
{
return st.data().shared_fields;
}

// connect
void boost::mysql::detail::connection_impl::connect_erased(
any_stream& stream,
connection_state& st,
const void* endpoint,
const handshake_params& params,
error_code& err,
diagnostics& diag
)
{
connect_impl(stream, st, endpoint, params, err, diag);
}

void boost::mysql::detail::connection_impl::async_connect_erased(
any_stream& stream,
connection_state& st,
const void* endpoint,
const handshake_params& params,
diagnostics& diag,
any_void_handler handler
)
{
async_connect_impl(stream, st, endpoint, params, diag, std::move(handler));
}

boost::mysql::detail::connection_impl::connection_impl(
std::size_t read_buff_size,
std::unique_ptr<any_stream> stream
Expand Down
71 changes: 0 additions & 71 deletions include/boost/mysql/impl/generic_algo.ipp

This file was deleted.

Loading

0 comments on commit 87a3244

Please sign in to comment.