Add asio client session callbacks to constructors

This commit is contained in:
pacevedom 2019-03-03 22:03:17 +01:00
parent f5feb16ef4
commit 93069e1bdd
2 changed files with 126 additions and 18 deletions

View File

@ -53,6 +53,27 @@ session::session(boost::asio::io_service &io_service,
impl_->start_resolve(host, service); impl_->start_resolve(host, service);
} }
session::session(boost::asio::io_service &io_service, const std::string &host,
const std::string &service, connect_cb ccb, error_cb ecb)
: impl_(std::make_shared<session_tcp_impl>(
io_service, host, service, boost::posix_time::seconds(60))) {
impl_->on_connect(ccb);
impl_->on_error(ecb);
impl_->start_resolve(host, service);
}
session::session(boost::asio::io_service &io_service,
const boost::asio::ip::tcp::endpoint &local_endpoint,
const std::string &host, const std::string &service,
connect_cb ccb, error_cb ecb)
: impl_(std::make_shared<session_tcp_impl>(
io_service, local_endpoint, host, service,
boost::posix_time::seconds(60))) {
impl_->on_connect(ccb);
impl_->on_error(ecb);
impl_->start_resolve(host, service);
}
session::session(boost::asio::io_service &io_service, const std::string &host, session::session(boost::asio::io_service &io_service, const std::string &host,
const std::string &service, const std::string &service,
const boost::posix_time::time_duration &connect_timeout) const boost::posix_time::time_duration &connect_timeout)
@ -70,6 +91,29 @@ session::session(boost::asio::io_service &io_service,
impl_->start_resolve(host, service); impl_->start_resolve(host, service);
} }
session::session(boost::asio::io_service &io_service, const std::string &host,
const std::string &service,
const boost::posix_time::time_duration &connect_timeout,
connect_cb ccb, error_cb ecb)
: impl_(std::make_shared<session_tcp_impl>(io_service, host, service,
connect_timeout)) {
impl_->on_connect(ccb);
impl_->on_error(ecb);
impl_->start_resolve(host, service);
}
session::session(boost::asio::io_service &io_service,
const boost::asio::ip::tcp::endpoint &local_endpoint,
const std::string &host, const std::string &service,
const boost::posix_time::time_duration &connect_timeout,
connect_cb ccb, error_cb ecb)
: impl_(std::make_shared<session_tcp_impl>(io_service, local_endpoint, host,
service, connect_timeout)) {
impl_->on_connect(ccb);
impl_->on_error(ecb);
impl_->start_resolve(host, service);
}
session::session(boost::asio::io_service &io_service, session::session(boost::asio::io_service &io_service,
boost::asio::ssl::context &tls_ctx, const std::string &host, boost::asio::ssl::context &tls_ctx, const std::string &host,
const std::string &service) const std::string &service)
@ -78,6 +122,16 @@ session::session(boost::asio::io_service &io_service,
impl_->start_resolve(host, service); impl_->start_resolve(host, service);
} }
session::session(boost::asio::io_service &io_service,
boost::asio::ssl::context &tls_ctx, const std::string &host,
const std::string &service, connect_cb ccb, error_cb ecb)
: impl_(std::make_shared<session_tls_impl>(
io_service, tls_ctx, host, service, boost::posix_time::seconds(60))) {
impl_->on_connect(ccb);
impl_->on_error(ecb);
impl_->start_resolve(host, service);
}
session::session(boost::asio::io_service &io_service, session::session(boost::asio::io_service &io_service,
boost::asio::ssl::context &tls_ctx, const std::string &host, boost::asio::ssl::context &tls_ctx, const std::string &host,
const std::string &service, const std::string &service,
@ -87,6 +141,18 @@ session::session(boost::asio::io_service &io_service,
impl_->start_resolve(host, service); impl_->start_resolve(host, service);
} }
session::session(boost::asio::io_service &io_service,
boost::asio::ssl::context &tls_ctx, const std::string &host,
const std::string &service,
const boost::posix_time::time_duration &connect_timeout,
connect_cb ccb, error_cb ecb)
: impl_(std::make_shared<session_tls_impl>(io_service, tls_ctx, host,
service, connect_timeout)) {
impl_->on_connect(ccb);
impl_->on_error(ecb);
impl_->start_resolve(host, service);
}
session::~session() {} session::~session() {}
session::session(session &&other) noexcept : impl_(std::move(other.impl_)) {} session::session(session &&other) noexcept : impl_(std::move(other.impl_)) {}

View File

@ -155,6 +155,18 @@ public:
const boost::asio::ip::tcp::endpoint &local_endpoint, const boost::asio::ip::tcp::endpoint &local_endpoint,
const std::string &host, const std::string &service); const std::string &host, const std::string &service);
// Starts HTTP/2 session by connecting to |host| and |service|
// (e.g., "80") using clear text TCP connection with connect timeout
// 60 seconds and given connect/error callbacks.
session(boost::asio::io_service &io_service, const std::string &host,
const std::string &service, connect_cb ccb, error_cb ecb);
// Same as previous but with pegged local endpoint
session(boost::asio::io_service &io_service,
const boost::asio::ip::tcp::endpoint &local_endpoint,
const std::string &host, const std::string &service, connect_cb ccb,
error_cb ecb);
// Starts HTTP/2 session by connecting to |host| and |service| // Starts HTTP/2 session by connecting to |host| and |service|
// (e.g., "80") using clear text TCP connection with given connect // (e.g., "80") using clear text TCP connection with given connect
// timeout. // timeout.
@ -168,6 +180,21 @@ public:
const std::string &host, const std::string &service, const std::string &host, const std::string &service,
const boost::posix_time::time_duration &connect_timeout); const boost::posix_time::time_duration &connect_timeout);
// Starts HTTP/2 session by connecting to |host| and |service|
// (e.g., "80") using clear text TCP connection with given connect
// timeout and connect/error callbacks.
session(boost::asio::io_service &io_service, const std::string &host,
const std::string &service,
const boost::posix_time::time_duration &connect_timeout,
connect_cb ccb, error_cb ecb);
// Same as previous but with pegged local endpoint
session(boost::asio::io_service &io_service,
const boost::asio::ip::tcp::endpoint &local_endpoint,
const std::string &host, const std::string &service,
const boost::posix_time::time_duration &connect_timeout,
connect_cb ccb, error_cb ecb);
// Starts HTTP/2 session by connecting to |host| and |service| // Starts HTTP/2 session by connecting to |host| and |service|
// (e.g., "443") using encrypted SSL/TLS connection with connect // (e.g., "443") using encrypted SSL/TLS connection with connect
// timeout 60 seconds. // timeout 60 seconds.
@ -175,6 +202,13 @@ public:
boost::asio::ssl::context &tls_context, const std::string &host, boost::asio::ssl::context &tls_context, const std::string &host,
const std::string &service); const std::string &service);
// Starts HTTP/2 session by connecting to |host| and |service|
// (e.g., "443") using encrypted SSL/TLS connection with connect
// timeout 60 seconds and connect/error callbacks.
session(boost::asio::io_service &io_service,
boost::asio::ssl::context &tls_context, const std::string &host,
const std::string &service, connect_cb ccb, error_cb ecb);
// Starts HTTP/2 session by connecting to |host| and |service| // Starts HTTP/2 session by connecting to |host| and |service|
// (e.g., "443") using encrypted SSL/TLS connection with given // (e.g., "443") using encrypted SSL/TLS connection with given
// connect timeout. // connect timeout.
@ -183,6 +217,15 @@ public:
const std::string &service, const std::string &service,
const boost::posix_time::time_duration &connect_timeout); const boost::posix_time::time_duration &connect_timeout);
// Starts HTTP/2 session by connecting to |host| and |service|
// (e.g., "443") using encrypted SSL/TLS connection with given
// connect timeout and connect/error callbacks.
session(boost::asio::io_service &io_service,
boost::asio::ssl::context &tls_context, const std::string &host,
const std::string &service,
const boost::posix_time::time_duration &connect_timeout,
connect_cb ccb, error_cb ecb);
~session(); ~session();
session(session &&other) noexcept; session(session &&other) noexcept;
@ -239,9 +282,8 @@ private:
// configure |tls_ctx| for client use. Currently, we just set NPN // configure |tls_ctx| for client use. Currently, we just set NPN
// callback for HTTP/2. // callback for HTTP/2.
boost::system::error_code boost::system::error_code configure_tls_context(
configure_tls_context(boost::system::error_code &ec, boost::system::error_code &ec, boost::asio::ssl::context &tls_ctx);
boost::asio::ssl::context &tls_ctx);
} // namespace client } // namespace client