From 15dd535c24046bfee181704eeef0f5f352fb5071 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 21 Nov 2018 11:29:10 -0800 Subject: [PATCH] Use bind_front_handler: The implementation uses bind_front_handler to reduce the resources consumed when instantiating templates during compilation. --- CHANGELOG.md | 1 + example/common/detect_ssl.hpp | 3 ++- .../beast/_experimental/test/impl/stream.ipp | 20 +++++++++---------- .../beast/core/impl/buffered_read_stream.ipp | 2 +- include/boost/beast/http/impl/read.ipp | 8 ++++---- include/boost/beast/http/impl/write.ipp | 4 ++-- include/boost/beast/websocket/impl/accept.ipp | 2 +- include/boost/beast/websocket/impl/close.ipp | 2 +- include/boost/beast/websocket/impl/ping.ipp | 2 +- include/boost/beast/websocket/impl/read.ipp | 4 ++-- .../boost/beast/websocket/impl/teardown.ipp | 2 +- include/boost/beast/websocket/impl/write.ipp | 4 +++- 12 files changed, 29 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20299dbd..7b96fded 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 191: * Add bind_front_handler +* Use bind_front_handler -------------------------------------------------------------------------------- diff --git a/example/common/detect_ssl.hpp b/example/common/detect_ssl.hpp index ee3e7dfb..8c322996 100644 --- a/example/common/detect_ssl.hpp +++ b/example/common/detect_ssl.hpp @@ -424,7 +424,8 @@ operator()(boost::beast::error_code ec, std::size_t bytes_transferred) BOOST_ASIO_CORO_YIELD boost::asio::post( stream_.get_executor(), - beast::bind_handler(std::move(*this), ec, 0)); + beast::bind_front_handler( + std::move(*this), ec, 0)); } else { diff --git a/include/boost/beast/_experimental/test/impl/stream.ipp b/include/boost/beast/_experimental/test/impl/stream.ipp index db963ba0..c7c53684 100644 --- a/include/boost/beast/_experimental/test/impl/stream.ipp +++ b/include/boost/beast/_experimental/test/impl/stream.ipp @@ -263,7 +263,7 @@ async_read_some( if(in_->fc->fail(ec)) return boost::asio::post( in_->ioc.get_executor(), - bind_handler( + bind_front_handler( std::move(init.completion_handler), ec, 0)); @@ -281,7 +281,7 @@ async_read_some( ++in_->nread; boost::asio::post( in_->ioc.get_executor(), - bind_handler( + bind_front_handler( std::move(init.completion_handler), error_code{}, bytes_transferred)); @@ -297,7 +297,7 @@ async_read_some( ec = boost::asio::error::connection_reset; boost::asio::post( in_->ioc.get_executor(), - bind_handler( + bind_front_handler( std::move(init.completion_handler), ec, 0)); @@ -380,7 +380,7 @@ async_write_some(ConstBufferSequence const& buffers, if(! out) return boost::asio::post( in_->ioc.get_executor(), - bind_handler( + bind_front_handler( std::move(init.completion_handler), boost::asio::error::connection_reset, 0)); @@ -391,7 +391,7 @@ async_write_some(ConstBufferSequence const& buffers, if(in_->fc->fail(ec)) return boost::asio::post( in_->ioc.get_executor(), - bind_handler( + bind_front_handler( std::move(init.completion_handler), ec, 0)); @@ -407,7 +407,7 @@ async_write_some(ConstBufferSequence const& buffers, ++in_->nwrite; boost::asio::post( in_->ioc.get_executor(), - bind_handler( + bind_front_handler( std::move(init.completion_handler), error_code{}, bytes_transferred)); @@ -447,7 +447,7 @@ TeardownHandler&& handler) s.in_->fc->fail(ec)) return boost::asio::post( s.get_executor(), - bind_handler(std::move(handler), ec)); + bind_front_handler(std::move(handler), ec)); s.close(); if( s.in_->fc && s.in_->fc->fail(ec)) @@ -457,7 +457,7 @@ TeardownHandler&& handler) boost::asio::post( s.get_executor(), - bind_handler(std::move(handler), ec)); + bind_front_handler(std::move(handler), ec)); } //------------------------------------------------------------------------------ @@ -513,7 +513,7 @@ class stream::read_op : public stream::read_op_base ++s.nread; boost::asio::post( s.ioc.get_executor(), - bind_handler( + bind_front_handler( std::move(h), error_code{}, bytes_transferred)); @@ -532,7 +532,7 @@ class stream::read_op : public stream::read_op_base ec = boost::asio::error::connection_reset; boost::asio::post( s.ioc.get_executor(), - bind_handler(std::move(h), ec, 0)); + bind_front_handler(std::move(h), ec, 0)); } } }; diff --git a/include/boost/beast/core/impl/buffered_read_stream.ipp b/include/boost/beast/core/impl/buffered_read_stream.ipp index b199ea06..3e3259a0 100644 --- a/include/boost/beast/core/impl/buffered_read_stream.ipp +++ b/include/boost/beast/core/impl/buffered_read_stream.ipp @@ -126,7 +126,7 @@ read_some_op::operator()( step_ = 3; return boost::asio::post( s_.get_executor(), - bind_handler(std::move(*this), ec, 0)); + bind_front_handler(std::move(*this), ec, 0)); case 1: // upcall diff --git a/include/boost/beast/http/impl/read.ipp b/include/boost/beast/http/impl/read.ipp index 42ce175d..ca9c8b9f 100644 --- a/include/boost/beast/http/impl/read.ipp +++ b/include/boost/beast/http/impl/read.ipp @@ -7,8 +7,8 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_HTTP_IMPL_READ_IPP_HPP -#define BOOST_BEAST_HTTP_IMPL_READ_IPP_HPP +#ifndef BOOST_BEAST_HTTP_IMPL_READ_IPP +#define BOOST_BEAST_HTTP_IMPL_READ_IPP #include #include @@ -182,7 +182,7 @@ operator()( BOOST_ASIO_CORO_YIELD boost::asio::post( s_.get_executor(), - bind_handler(std::move(*this), + bind_front_handler(std::move(*this), ec, bytes_transferred_)); } h_(ec, bytes_transferred_); @@ -305,7 +305,7 @@ operator()( { BOOST_ASIO_CORO_YIELD boost::asio::post(s_.get_executor(), - bind_handler(std::move(*this), ec)); + bind_front_handler(std::move(*this), ec)); goto upcall; } for(;;) diff --git a/include/boost/beast/http/impl/write.ipp b/include/boost/beast/http/impl/write.ipp index 63f8a5ca..e5d5df9d 100644 --- a/include/boost/beast/http/impl/write.ipp +++ b/include/boost/beast/http/impl/write.ipp @@ -147,7 +147,7 @@ operator()() BOOST_ASSERT(! f.invoked); return boost::asio::post( s_.get_executor(), - bind_handler(std::move(*this), ec, 0)); + bind_front_handler(std::move(*this), ec, 0)); } if(f.invoked) { @@ -160,7 +160,7 @@ operator()() } return boost::asio::post( s_.get_executor(), - bind_handler(std::move(*this), ec, 0)); + bind_front_handler(std::move(*this), ec, 0)); } template< diff --git a/include/boost/beast/websocket/impl/accept.ipp b/include/boost/beast/websocket/impl/accept.ipp index 5a322990..393ad229 100644 --- a/include/boost/beast/websocket/impl/accept.ipp +++ b/include/boost/beast/websocket/impl/accept.ipp @@ -269,7 +269,7 @@ operator()(error_code ec, std::size_t) BOOST_ASIO_CORO_YIELD boost::asio::post( d.ws.get_executor(), - bind_handler(std::move(*this), ec)); + bind_front_handler(std::move(*this), ec)); } else { diff --git a/include/boost/beast/websocket/impl/close.ipp b/include/boost/beast/websocket/impl/close.ipp index 62ddffa2..762d7821 100644 --- a/include/boost/beast/websocket/impl/close.ipp +++ b/include/boost/beast/websocket/impl/close.ipp @@ -304,7 +304,7 @@ operator()( BOOST_ASIO_CORO_YIELD boost::asio::post( d.ws.get_executor(), - bind_handler(std::move(*this), ec)); + bind_front_handler(std::move(*this), ec)); } { auto wg = std::move(d.wg); diff --git a/include/boost/beast/websocket/impl/ping.ipp b/include/boost/beast/websocket/impl/ping.ipp index 6ceaaeab..f7fecd62 100644 --- a/include/boost/beast/websocket/impl/ping.ipp +++ b/include/boost/beast/websocket/impl/ping.ipp @@ -140,7 +140,7 @@ operator()(error_code ec, std::size_t) BOOST_ASIO_CORO_YIELD boost::asio::post( d.ws.get_executor(), - bind_handler(std::move(*this), ec)); + bind_front_handler(std::move(*this), ec)); goto upcall; } } diff --git a/include/boost/beast/websocket/impl/read.ipp b/include/boost/beast/websocket/impl/read.ipp index 3fb7f223..cfcbe8be 100644 --- a/include/boost/beast/websocket/impl/read.ipp +++ b/include/boost/beast/websocket/impl/read.ipp @@ -705,7 +705,7 @@ operator()( BOOST_ASIO_CORO_YIELD boost::asio::post( ws_.get_executor(), - bind_handler(std::move(*this), + bind_front_handler(std::move(*this), ec, bytes_written_)); } h_(ec, bytes_written_); @@ -813,7 +813,7 @@ operator()( if(ec) boost::asio::post( ws_.get_executor(), - bind_handler( + bind_front_handler( std::move(*this), ec, 0)); else read_some_op