Alternative of boost::asio::executor_work_guard for older boost version (1.57)

Viewed 41

I need my boost::asio::io_service object prevent from exiting when there is no more work to do. The boost.asio library version that we are using is outdated and we are not yet allowed to upgrade. The 1.57 version we are using seems not to contain the boost:asio::executor_work_guard that could prevent the io_service object from exiting. Are there any known alternatives to it in the old boost.asio version 1.57 (Linux)?

1 Answers

In older versions you'd use a io_service::work object:

boost::asio::io_service io;
boost::asio::work work(io);

Note that to get reset() like functionality you'd wrap that in boost::optional<> or std::unique_ptr<>

This is actually still in the documentation for the 1.57.0 version in the same place(s) where you'd find executor_work_guard in newer versions, e.g. https://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/reference/io_service.html#boost_asio.reference.io_service.stopping_the_io_service_from_running_out_of_work

Related