Remove the use of bind_executor in basic_stream:

Use the executor hook instead of `bind_executor` to avoid template
instantiations.

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek
2019-05-19 19:11:47 +02:00
parent dcf3db7f83
commit 0f77bd7149
2 changed files with 107 additions and 103 deletions

View File

@@ -284,6 +284,7 @@ private:
// but the implementation is still waiting on a timer.
boost::shared_ptr<impl_type> impl_;
template<class Executor2>
struct timeout_handler;
struct ops;

View File

@@ -15,7 +15,6 @@
#include <boost/beast/core/buffers_prefix.hpp>
#include <boost/beast/core/detail/type_traits.hpp>
#include <boost/beast/websocket/teardown.hpp>
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/coroutine.hpp>
#include <boost/assert.hpp>
#include <boost/make_shared.hpp>
@@ -161,12 +160,21 @@ close()
//------------------------------------------------------------------------------
template<class Protocol, class Executor, class RatePolicy>
template<class Executor2>
struct basic_stream<Protocol, Executor, RatePolicy>::
timeout_handler
{
using executor_type = Executor2;
op_state& state;
boost::weak_ptr<impl_type> wp;
tick_type tick;
executor_type ex;
executor_type get_executor() const noexcept
{
return ex;
}
void
operator()(error_code ec)
@@ -329,13 +337,11 @@ public:
// if a timeout is active, wait on the timer
if(state().timer.expiry() != never())
state().timer.async_wait(
net::bind_executor(
this->get_executor(),
timeout_handler{
timeout_handler<decltype(this->get_executor())>{
state(),
impl_,
state().tick
}));
state().tick,
this->get_executor()});
// check rate limit, maybe wait
std::size_t amount;
@@ -430,12 +436,11 @@ public:
{
if(state().timer.expiry() != stream_base::never())
impl_->write.timer.async_wait(
net::bind_executor(
this->get_executor(),
timeout_handler{
timeout_handler<decltype(this->get_executor())>{
state(),
impl_,
state().tick}));
state().tick,
this->get_executor()});
impl_->socket.async_connect(
ep, std::move(*this));
@@ -458,12 +463,11 @@ public:
{
if(state().timer.expiry() != stream_base::never())
impl_->write.timer.async_wait(
net::bind_executor(
this->get_executor(),
timeout_handler{
timeout_handler<decltype(this->get_executor())>{
state(),
impl_,
state().tick}));
state().tick,
this->get_executor()});
net::async_connect(impl_->socket,
eps, cond, std::move(*this));
@@ -486,12 +490,11 @@ public:
{
if(state().timer.expiry() != stream_base::never())
impl_->write.timer.async_wait(
net::bind_executor(
this->get_executor(),
timeout_handler{
timeout_handler<decltype(this->get_executor())>{
state(),
impl_,
state().tick}));
state().tick,
this->get_executor()});
net::async_connect(impl_->socket,
begin, end, cond, std::move(*this));