From 214fa12f21461a9aa904ebbf47f0b28fed9a11f0 Mon Sep 17 00:00:00 2001 From: Damian Jarek Date: Mon, 17 Jun 2019 00:38:35 +0200 Subject: [PATCH] Use `beast::read_size` in `detail::read` This allows using the read size hint and deduplicates a fairly complicated piece of code. Signed-off-by: Damian Jarek --- CHANGELOG.md | 1 + include/boost/beast/core/detail/impl/read.hpp | 17 +++-------------- include/boost/beast/core/impl/read_size.hpp | 1 - 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37bdd5be..10f456c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Version 259: * Improve performance of `http::string_to_verb` * Replace uses of `net::coroutine` with `asio::coroutine` * Replace uses of `net::spawn` with `asio::spawn` +* Use `beast::read_size` in `detail::read` -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/detail/impl/read.hpp b/include/boost/beast/core/detail/impl/read.hpp index c0e997ae..37249792 100644 --- a/include/boost/beast/core/detail/impl/read.hpp +++ b/include/boost/beast/core/detail/impl/read.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -73,18 +74,12 @@ public: std::size_t bytes_transferred, bool cont = true) { - std::size_t max_size; std::size_t max_prepare; BOOST_ASIO_CORO_REENTER(*this) { for(;;) { - max_size = cond_(ec, total_, b_); - max_prepare = std::min( - std::max( - 512, b_.capacity() - b_.size()), - std::min( - max_size, b_.max_size() - b_.size())); + max_prepare = beast::read_size(b_, cond_(ec, total_, b_)); if(max_prepare == 0) break; BOOST_ASIO_CORO_YIELD @@ -201,16 +196,10 @@ read( "CompletionCondition type requirements not met"); ec = {}; std::size_t total = 0; - std::size_t max_size; std::size_t max_prepare; for(;;) { - max_size = cond(ec, total, buffer); - max_prepare = std::min( - std::max( - 512, buffer.capacity() - buffer.size()), - std::min( - max_size, buffer.max_size() - buffer.size())); + max_prepare = beast::read_size(buffer, cond(ec, total, buffer)); if(max_prepare == 0) break; std::size_t const bytes_transferred = diff --git a/include/boost/beast/core/impl/read_size.hpp b/include/boost/beast/core/impl/read_size.hpp index 1896c014..babbcaac 100644 --- a/include/boost/beast/core/impl/read_size.hpp +++ b/include/boost/beast/core/impl/read_size.hpp @@ -46,7 +46,6 @@ read_size(DynamicBuffer& buffer, static_assert( net::is_dynamic_buffer::value, "DynamicBuffer type requirements not met"); - BOOST_ASSERT(max_size >= 1); auto const size = buffer.size(); auto const limit = buffer.max_size() - size; BOOST_ASSERT(size <= buffer.max_size());