Skip to content
Snippets Groups Projects
Commit 52c2feb2 authored by Konstantinos Sideris's avatar Konstantinos Sideris
Browse files

Manage the work object with optional instead of unique_ptr

parent 0211ae0f
No related branches found
No related tags found
No related merge requests found
#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();
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment