From 52c2feb213b29461c6a55d4525f507779d1d9ba9 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris <sideris.konstantin@gmail.com> Date: Wed, 11 Apr 2018 14:38:41 +0300 Subject: [PATCH] Manage the work object with optional instead of unique_ptr --- src/client.cpp | 6 ++++-- src/client.hpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 6e42dcaaf..bb8a7e324 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1,5 +1,6 @@ #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> +#include <boost/utility/typed_in_place_factory.hpp> #include "client.hpp" #include "utils.hpp" @@ -15,7 +16,8 @@ Client::Client(const std::string &server, uint16_t port) , server_{server} , port_{port} { - work_.reset(new boost::asio::io_service::work(ios_)); + using namespace boost::asio; + work_ = boost::in_place<io_service::work>(io_service::work(ios_)); const auto threads_num = std::max(1U, std::thread::hardware_concurrency()); @@ -29,7 +31,7 @@ Client::close() // Destroy work object. This allows the I/O thread to // exit the event loop when there are no more pending // asynchronous operations. - work_.reset(nullptr); + work_ = boost::none; // Wait for the worker threads to exit. thread_group_.join_all(); diff --git a/src/client.hpp b/src/client.hpp index 84c36f2b1..63561eb98 100644 --- a/src/client.hpp +++ b/src/client.hpp @@ -291,7 +291,7 @@ private: boost::asio::io_service ios_; //! Used to prevent the event loop from shutting down. - std::unique_ptr<boost::asio::io_service::work> work_; + boost::optional<boost::asio::io_service::work> work_; //! Worker threads for the requests. boost::thread_group thread_group_; //! Used to resolve DNS names. -- GitLab