Use executor_work_guard in composed operations:

fix #1076

As per Asio and Networking TS requirements, composed operations must
maintain an object of type executor_work_guard for the executor associated
with the I/O object, for the lifetime of the asynchronous operation.

This is in addition to the requirement for maintaining an object of type
executor_work_guard for the executor associated with the handler.
This commit is contained in:
Vinnie Falco committed 2018-04-10 08:03:04 -07:00
1 parent b4cb4f1fd3
commit 86342dd72b
18 files changed
+154 -34

No files matched your search

@@ -19,6 +19,7 @@
#include <boost/beast/test/fail_counter.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/post.hpp>
#include <boost/assert.hpp>
@@ -697,9 +698,8 @@ class stream::read_op_impl : public stream::read_op
state& s_;
Buffers b_;
Handler h_;
boost::optional<
boost::asio::executor_work_guard<
boost::asio::io_context::executor_type>> work_;
boost::asio::executor_work_guard<
boost::asio::io_context::executor_type> work_;
public:
lambda(lambda&&) = default;
@@ -720,7 +720,7 @@ class stream::read_op_impl : public stream::read_op
boost::asio::post(
s_.ioc.get_executor(),
std::move(*this));
work_ = boost::none;
work_.reset();
}
void
@@ -10,9 +10,9 @@
#ifndef BOOST_BEAST_TEST_YIELD_TO_HPP
#define BOOST_BEAST_TEST_YIELD_TO_HPP
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/optional.hpp>
#include <condition_variable>
#include <functional>
#include <mutex>
@@ -35,9 +35,8 @@ protected:
boost::asio::io_context ioc_;
private:
boost::optional<
boost::asio::executor_work_guard<
boost::asio::io_context::executor_type>> work_;
boost::asio::executor_work_guard<
boost::asio::io_context::executor_type> work_;
std::vector<std::thread> threads_;
std::mutex m_;
std::condition_variable cv_;
@@ -60,7 +59,7 @@ public:
~enable_yield_to()
{
work_ = boost::none;
work_.reset();
for(auto& t : threads_)
t.join();
}