From 3847ef5f7b22f039bb50cdf9809f6b3511b63477 Mon Sep 17 00:00:00 2001 From: Nicolas Werner <nicolas.werner@hotmail.de> Date: Mon, 8 Mar 2021 05:06:38 +0100 Subject: [PATCH] Replace deprecated asio names --- include/mtxclient/http/session.hpp | 3 ++- lib/http/client.cpp | 13 +++++++------ lib/http/session.cpp | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/mtxclient/http/session.hpp b/include/mtxclient/http/session.hpp index 3ae18aa6e..89c7711b3 100644 --- a/include/mtxclient/http/session.hpp +++ b/include/mtxclient/http/session.hpp @@ -7,6 +7,7 @@ #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> +#include <boost/asio/strand.hpp> #include <boost/beast.hpp> #include <nlohmann/json.hpp> @@ -33,7 +34,7 @@ using FailureCallback = //! Represents a context of a single request. struct Session : public std::enable_shared_from_this<Session> { - Session(boost::asio::io_service &ios, + Session(boost::asio::strand<boost::asio::io_context::executor_type> ios, boost::asio::ssl::context &ssl_ctx, const std::string &host, uint16_t port, diff --git a/lib/http/client.cpp b/lib/http/client.cpp index 8595e53e0..8e4334eee 100644 --- a/lib/http/client.cpp +++ b/lib/http/client.cpp @@ -28,9 +28,10 @@ using namespace boost::beast; namespace mtx::http { struct ClientPrivate { - boost::asio::io_service ios_; + boost::asio::io_context ioc_; //! Used to prevent the event loop from shutting down. - std::optional<boost::asio::io_context::work> work_{ios_}; + boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_{ + ioc_.get_executor()}; //! Worker threads for the requests. boost::thread_group thread_group_; //! SSL context for requests. @@ -56,7 +57,7 @@ Client::Client(const std::string &server, uint16_t port) p->ssl_ctx_.set_verify_callback(ssl::rfc2818_verification(server)); for (unsigned int i = 0; i < threads_num; ++i) - p->thread_group_.add_thread(new boost::thread([this]() { p->ios_.run(); })); + p->thread_group_.add_thread(new boost::thread([this]() { p->ioc_.run(); })); } // call destuctor of work queue and ios first! @@ -66,8 +67,8 @@ std::shared_ptr<Session> Client::create_session(TypeErasedCallback type_erased_cb) { auto session = std::make_shared<Session>( - std::ref(p->ios_), - std::ref(p->ssl_ctx_), + boost::asio::make_strand(p->ioc_), + p->ssl_ctx_, server_, port_, client::utils::random_token(), @@ -247,7 +248,7 @@ Client::close(bool force) // We close all open connections. if (force) { shutdown(); - p->ios_.stop(); + p->ioc_.stop(); } // Destroy work object. This allows the I/O thread to diff --git a/lib/http/session.cpp b/lib/http/session.cpp index 2cdcbe21a..dd0ba09fe 100644 --- a/lib/http/session.cpp +++ b/lib/http/session.cpp @@ -6,7 +6,7 @@ using namespace mtx::http; -Session::Session(boost::asio::io_service &ios, +Session::Session(boost::asio::strand<boost::asio::io_context::executor_type> ios, boost::asio::ssl::context &ssl_ctx, const std::string &host, uint16_t port, @@ -17,8 +17,8 @@ Session::Session(boost::asio::io_service &ios, // I don't know, if we need to use the same strand for both the socket and the resolver or if one // for each works as well. Taken from this example: // https://www.boost.org/doc/libs/1_71_0/libs/beast/example/http/client/async-ssl/http_client_async_ssl.cpp - : resolver_(boost::asio::make_strand(ios)) - , socket(boost::asio::make_strand(ios), ssl_ctx) + : resolver_(ios) + , socket(ios, ssl_ctx) , host(std::move(host)) , port{port} , id(std::move(id)) -- GitLab