mirror of
https://github.com/boostorg/mysql.git
synced 2026-02-14 12:52:17 +00:00
Split socket-specific methods to socket_connection
This commit is contained in:
@@ -65,6 +65,8 @@ class connection
|
||||
|
||||
Stream next_layer_;
|
||||
channel_type channel_;
|
||||
protected:
|
||||
channel_type& get_channel() noexcept { return channel_; }
|
||||
public:
|
||||
/**
|
||||
* \brief Initializing constructor.
|
||||
@@ -113,20 +115,6 @@ public:
|
||||
BOOST_MYSQL_INITFN_RESULT_TYPE(CompletionToken, handshake_signature)
|
||||
async_handshake(const connection_params& params, CompletionToken&& token, error_info* info = nullptr);
|
||||
|
||||
template <typename EndpointType>
|
||||
void connect(const EndpointType& endpoint, const connection_params& params,
|
||||
error_code& ec, error_info& info);
|
||||
|
||||
template <typename EndpointType>
|
||||
void connect(const EndpointType& endpoint, const connection_params& params);
|
||||
|
||||
using connect_signature = void(error_code);
|
||||
|
||||
template <typename EndpointType, typename CompletionToken>
|
||||
BOOST_MYSQL_INITFN_RESULT_TYPE(CompletionToken, connect_signature)
|
||||
async_connect(const EndpointType& endpoint, const connection_params& params,
|
||||
CompletionToken&& token, error_info* output_info=nullptr);
|
||||
|
||||
/**
|
||||
* \brief Executes a SQL text query (sync with error code version).
|
||||
* \details Does not perform the actual retrieval of the data; use the various
|
||||
@@ -208,6 +196,28 @@ public:
|
||||
template <typename CompletionToken>
|
||||
BOOST_MYSQL_INITFN_RESULT_TYPE(CompletionToken, quit_signature)
|
||||
async_quit(CompletionToken&& token, error_info* info=nullptr);
|
||||
};
|
||||
|
||||
template<
|
||||
typename Stream
|
||||
>
|
||||
class socket_connection : public connection<Stream>
|
||||
{
|
||||
public:
|
||||
using connection<Stream>::connection;
|
||||
using endpoint_type = typename Stream::endpoint_type;
|
||||
|
||||
void connect(const endpoint_type& endpoint, const connection_params& params,
|
||||
error_code& ec, error_info& info);
|
||||
|
||||
void connect(const endpoint_type& endpoint, const connection_params& params);
|
||||
|
||||
using connect_signature = void(error_code);
|
||||
|
||||
template <typename CompletionToken>
|
||||
BOOST_MYSQL_INITFN_RESULT_TYPE(CompletionToken, connect_signature)
|
||||
async_connect(const endpoint_type& endpoint, const connection_params& params,
|
||||
CompletionToken&& token, error_info* output_info=nullptr);
|
||||
|
||||
/**
|
||||
* \brief Closes the connection (sync with error code version).
|
||||
@@ -241,7 +251,7 @@ public:
|
||||
* \ingroup connection
|
||||
* \brief A connection to MySQL over a TCP socket.
|
||||
*/
|
||||
using tcp_connection = connection<boost::asio::ip::tcp::socket>;
|
||||
using tcp_connection = socket_connection<boost::asio::ip::tcp::socket>;
|
||||
|
||||
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) || defined(BOOST_MYSQL_DOXYGEN)
|
||||
|
||||
@@ -249,7 +259,7 @@ using tcp_connection = connection<boost::asio::ip::tcp::socket>;
|
||||
* \ingroup connection
|
||||
* \brief A connection to MySQL over a UNIX domain socket.
|
||||
*/
|
||||
using unix_connection = connection<boost::asio::local::stream_protocol::socket>;
|
||||
using unix_connection = socket_connection<boost::asio::local::stream_protocol::socket>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace boost {
|
||||
namespace mysql {
|
||||
namespace detail {
|
||||
|
||||
template <typename StreamType, typename EndpointType>
|
||||
template <typename StreamType>
|
||||
void connect(
|
||||
channel<StreamType>& chan,
|
||||
const EndpointType& endpoint,
|
||||
const typename StreamType::endpoint_type& endpoint,
|
||||
const connection_params& params,
|
||||
error_code& err,
|
||||
error_info& info
|
||||
@@ -26,11 +26,11 @@ void connect(
|
||||
|
||||
using connect_signature = empty_signature;
|
||||
|
||||
template <typename StreamType, typename EndpointType, typename CompletionToken>
|
||||
template <typename StreamType, typename CompletionToken>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, connect_signature)
|
||||
async_connect(
|
||||
channel<StreamType>& chan,
|
||||
const EndpointType& endpoint,
|
||||
const typename StreamType::endpoint_type& endpoint,
|
||||
const connection_params& params,
|
||||
CompletionToken&& token,
|
||||
error_info* info
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
#include "boost/mysql/detail/network_algorithms/handshake.hpp"
|
||||
|
||||
template <typename StreamType, typename EndpointType>
|
||||
template <typename StreamType>
|
||||
void boost::mysql::detail::connect(
|
||||
channel<StreamType>& chan,
|
||||
const EndpointType& endpoint,
|
||||
const typename StreamType::endpoint_type& endpoint,
|
||||
const connection_params& params,
|
||||
error_code& err,
|
||||
error_info& info
|
||||
@@ -33,29 +33,30 @@ void boost::mysql::detail::connect(
|
||||
}
|
||||
}
|
||||
|
||||
template <typename StreamType, typename EndpointType, typename CompletionToken>
|
||||
template <typename StreamType, typename CompletionToken>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(
|
||||
CompletionToken,
|
||||
boost::mysql::detail::connect_signature
|
||||
)
|
||||
boost::mysql::detail::async_connect(
|
||||
channel<StreamType>& chan,
|
||||
const EndpointType& endpoint,
|
||||
const typename StreamType::endpoint_type& endpoint,
|
||||
const connection_params& params,
|
||||
CompletionToken&& token,
|
||||
error_info* info
|
||||
)
|
||||
{
|
||||
using endpoint_type = typename StreamType::endpoint_type;
|
||||
struct op : async_op<StreamType, CompletionToken, connect_signature, op>
|
||||
{
|
||||
const EndpointType& ep_;
|
||||
const endpoint_type& ep_; // No need for a copy, as we will call it in the first operator() call
|
||||
connection_params params_;
|
||||
|
||||
op(
|
||||
boost::asio::async_completion<CompletionToken, connect_signature>& completion,
|
||||
channel<StreamType>& chan,
|
||||
error_info* output_info,
|
||||
const EndpointType& ep,
|
||||
const endpoint_type& ep,
|
||||
const connection_params& params
|
||||
) :
|
||||
async_op<StreamType, CompletionToken, connect_signature, op>(completion, chan, output_info),
|
||||
|
||||
@@ -61,50 +61,6 @@ boost::mysql::connection<Stream>::async_handshake(
|
||||
);
|
||||
}
|
||||
|
||||
// connect
|
||||
template <typename Stream>
|
||||
template <typename EndpointType>
|
||||
void boost::mysql::connection<Stream>::connect(
|
||||
const EndpointType& endpoint,
|
||||
const connection_params& params,
|
||||
error_code& ec,
|
||||
error_info& info
|
||||
)
|
||||
{
|
||||
detail::clear_errors(ec, info);
|
||||
detail::connect(channel_, endpoint, params, ec, info);
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
template <typename EndpointType>
|
||||
void boost::mysql::connection<Stream>::connect(
|
||||
const EndpointType& endpoint,
|
||||
const connection_params& params
|
||||
)
|
||||
{
|
||||
detail::error_block blk;
|
||||
detail::connect(channel_, endpoint, params, blk.err, blk.info);
|
||||
blk.check();
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
template <typename EndpointType, typename CompletionToken>
|
||||
BOOST_MYSQL_INITFN_RESULT_TYPE(
|
||||
CompletionToken,
|
||||
typename boost::mysql::connection<Stream>::connect_signature
|
||||
)
|
||||
boost::mysql::connection<Stream>::async_connect(
|
||||
const EndpointType& endpoint,
|
||||
const connection_params& params,
|
||||
CompletionToken&& token,
|
||||
error_info* output_info
|
||||
)
|
||||
{
|
||||
detail::conditional_clear(output_info);
|
||||
detail::check_completion_token<CompletionToken, connect_signature>();
|
||||
return detail::async_connect(channel_, endpoint, params, std::forward<CompletionToken>(token), output_info);
|
||||
}
|
||||
|
||||
// Query
|
||||
template <typename Stream>
|
||||
boost::mysql::resultset<Stream> boost::mysql::connection<Stream>::query(
|
||||
@@ -238,21 +194,27 @@ boost::mysql::connection<Stream>::async_quit(
|
||||
);
|
||||
}
|
||||
|
||||
// socket_connection: connect
|
||||
template <typename Stream>
|
||||
void boost::mysql::connection<Stream>::close(
|
||||
error_code& err,
|
||||
void boost::mysql::socket_connection<Stream>::connect(
|
||||
const endpoint_type& endpoint,
|
||||
const connection_params& params,
|
||||
error_code& ec,
|
||||
error_info& info
|
||||
)
|
||||
{
|
||||
detail::clear_errors(err, info);
|
||||
detail::close_connection(channel_, err, info);
|
||||
detail::clear_errors(ec, info);
|
||||
detail::connect(this->get_channel(), endpoint, params, ec, info);
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
void boost::mysql::connection<Stream>::close()
|
||||
void boost::mysql::socket_connection<Stream>::connect(
|
||||
const endpoint_type& endpoint,
|
||||
const connection_params& params
|
||||
)
|
||||
{
|
||||
detail::error_block blk;
|
||||
detail::close_connection(channel_, blk.err, blk.info);
|
||||
detail::connect(this->get_channel(), endpoint, params, blk.err, blk.info);
|
||||
blk.check();
|
||||
}
|
||||
|
||||
@@ -260,9 +222,51 @@ template <typename Stream>
|
||||
template <typename CompletionToken>
|
||||
BOOST_MYSQL_INITFN_RESULT_TYPE(
|
||||
CompletionToken,
|
||||
typename boost::mysql::connection<Stream>::close_signature
|
||||
typename boost::mysql::socket_connection<Stream>::connect_signature
|
||||
)
|
||||
boost::mysql::connection<Stream>::async_close(
|
||||
boost::mysql::socket_connection<Stream>::async_connect(
|
||||
const endpoint_type& endpoint,
|
||||
const connection_params& params,
|
||||
CompletionToken&& token,
|
||||
error_info* output_info
|
||||
)
|
||||
{
|
||||
detail::conditional_clear(output_info);
|
||||
detail::check_completion_token<CompletionToken, connect_signature>();
|
||||
return detail::async_connect(
|
||||
this->get_channel(),
|
||||
endpoint,
|
||||
params,
|
||||
std::forward<CompletionToken>(token),
|
||||
output_info
|
||||
);
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
void boost::mysql::socket_connection<Stream>::close(
|
||||
error_code& err,
|
||||
error_info& info
|
||||
)
|
||||
{
|
||||
detail::clear_errors(err, info);
|
||||
detail::close_connection(this->get_channel(), err, info);
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
void boost::mysql::socket_connection<Stream>::close()
|
||||
{
|
||||
detail::error_block blk;
|
||||
detail::close_connection(this->get_channel(), blk.err, blk.info);
|
||||
blk.check();
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
template <typename CompletionToken>
|
||||
BOOST_MYSQL_INITFN_RESULT_TYPE(
|
||||
CompletionToken,
|
||||
typename boost::mysql::socket_connection<Stream>::close_signature
|
||||
)
|
||||
boost::mysql::socket_connection<Stream>::async_close(
|
||||
CompletionToken&& token,
|
||||
error_info* info
|
||||
)
|
||||
@@ -270,7 +274,7 @@ boost::mysql::connection<Stream>::async_close(
|
||||
detail::conditional_clear(info);
|
||||
detail::check_completion_token<CompletionToken, close_signature>();
|
||||
return detail::async_close_connection(
|
||||
channel_,
|
||||
this->get_channel(),
|
||||
std::forward<CompletionToken>(token),
|
||||
info
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
using namespace boost::mysql::test;
|
||||
using boost::mysql::error_code;
|
||||
using boost::mysql::connection;
|
||||
using boost::mysql::socket_connection;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -57,7 +57,7 @@ struct CloseConnectionTest : public NetworkTest<Stream>
|
||||
network_functions<Stream>* net = this->GetParam().net;
|
||||
|
||||
// An unconnected connection
|
||||
connection<Stream> not_opened_conn (this->ctx);
|
||||
socket_connection<Stream> not_opened_conn (this->ctx);
|
||||
|
||||
// Close
|
||||
auto result = net->close(not_opened_conn);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "integration_test_common.hpp"
|
||||
|
||||
using namespace boost::mysql::test;
|
||||
using boost::mysql::connection;
|
||||
using boost::mysql::socket_connection;
|
||||
using boost::mysql::errc;
|
||||
using boost::mysql::error_code;
|
||||
|
||||
@@ -19,7 +19,7 @@ template <typename Stream>
|
||||
struct ConnectTest : NetworkTest<Stream>
|
||||
{
|
||||
network_functions<Stream>* net;
|
||||
connection<Stream> other_conn;
|
||||
socket_connection<Stream> other_conn;
|
||||
|
||||
ConnectTest():
|
||||
net(this->GetParam().net),
|
||||
|
||||
@@ -45,7 +45,7 @@ struct IntegTest : testing::Test
|
||||
"boost_mysql_integtests"
|
||||
};
|
||||
boost::asio::io_context ctx;
|
||||
mysql::connection<Stream> conn {ctx};
|
||||
mysql::socket_connection<Stream> conn {ctx};
|
||||
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> guard { ctx.get_executor() };
|
||||
std::thread runner {[this]{ ctx.run(); } };
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ template <typename Stream>
|
||||
class network_functions
|
||||
{
|
||||
public:
|
||||
using connection_type = connection<Stream>;
|
||||
using connection_type = socket_connection<Stream>;
|
||||
using prepared_statement_type = prepared_statement<Stream>;
|
||||
using resultset_type = resultset<Stream>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user