From 65cbc158cf53a78272ee35866e860b1e73959a85 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 14 Feb 2019 07:52:56 -0800 Subject: [PATCH] Tidy up example docs and some names fix #1450 --- example/echo-op/echo_op.cpp | 9 +++++++-- include/boost/beast/core/async_op_base.hpp | 10 +++++----- include/boost/beast/core/impl/saved_handler.hpp | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/example/echo-op/echo_op.cpp b/example/echo-op/echo_op.cpp index 7c6af2f2..6f13966e 100644 --- a/example/echo-op/echo_op.cpp +++ b/example/echo-op/echo_op.cpp @@ -140,8 +140,13 @@ async_echo( // The class template `async_op_base` holds the caller's completion // handler for us, and provides all of the boilerplate for forwarding // the associated allocator and associated executor from the caller's - // handler to our operation. We declare this type alias to make the - // code easier to read. + // handler to our operation. It also maintains a `net::executor_work_guard` + // for the executor associated with the stream. This work guard is + // inexpensive, and prevents the execution context from running out + // of work. It is usually necessary although rarely it can be skipped + // depending on the operation (this echo example needs it because it + // performs more than one asynchronous operation in a row). + // We declare this type alias to make the code easier to read. using base_type = beast::async_op_base< handler_type, /*< The type of the completion handler obtained from the token >*/ diff --git a/include/boost/beast/core/async_op_base.hpp b/include/boost/beast/core/async_op_base.hpp index f44e51c7..0a90a283 100644 --- a/include/boost/beast/core/async_op_base.hpp +++ b/include/boost/beast/core/async_op_base.hpp @@ -188,7 +188,7 @@ class async_op_base "Executor requirements not met"); Handler h_; - net::executor_work_guard wg_; + net::executor_work_guard wg1_; virtual void @@ -230,7 +230,7 @@ public: Handler_&& handler, Executor1 const& ex1) : h_(std::forward(handler)) - , wg_(ex1) + , wg1_(ex1) { } @@ -242,7 +242,7 @@ public: : boost::empty_value( boost::empty_init_t{}, alloc) , h_(std::forward(handler)) - , wg_(ex1) + , wg1_(ex1) { } #endif @@ -291,7 +291,7 @@ public: get_executor() const noexcept { return net::get_associated_executor( - h_, wg_.get_executor()); + h_, wg1_.get_executor()); } /// Returns the handler associated with this object @@ -329,7 +329,7 @@ public: invoke(Args&&... args) { this->before_invoke_hook(); - wg_.reset(); + wg1_.reset(); h_(std::forward(args)...); } diff --git a/include/boost/beast/core/impl/saved_handler.hpp b/include/boost/beast/core/impl/saved_handler.hpp index d1ef2bf7..47f20275 100644 --- a/include/boost/beast/core/impl/saved_handler.hpp +++ b/include/boost/beast/core/impl/saved_handler.hpp @@ -65,13 +65,13 @@ class saved_handler::impl final : public base ebo_pair v_; net::executor_work_guard< - net::associated_executor_t> wg_; + net::associated_executor_t> wg2_; public: template impl(alloc_type const& a, Handler_&& h) : v_(a, std::forward(h)) - , wg_(net::get_associated_executor(v_.h)) + , wg2_(net::get_associated_executor(v_.h)) { }