mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 04:47:29 +02:00
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 <damian.jarek93@gmail.com>
This commit is contained in:
@ -12,6 +12,7 @@ Version 259:
|
|||||||
* Improve performance of `http::string_to_verb`
|
* Improve performance of `http::string_to_verb`
|
||||||
* Replace uses of `net::coroutine` with `asio::coroutine`
|
* Replace uses of `net::coroutine` with `asio::coroutine`
|
||||||
* Replace uses of `net::spawn` with `asio::spawn`
|
* Replace uses of `net::spawn` with `asio::spawn`
|
||||||
|
* Use `beast::read_size` in `detail::read`
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <boost/beast/core/bind_handler.hpp>
|
#include <boost/beast/core/bind_handler.hpp>
|
||||||
#include <boost/beast/core/async_base.hpp>
|
#include <boost/beast/core/async_base.hpp>
|
||||||
#include <boost/beast/core/flat_static_buffer.hpp>
|
#include <boost/beast/core/flat_static_buffer.hpp>
|
||||||
|
#include <boost/beast/core/read_size.hpp>
|
||||||
#include <boost/asio/basic_stream_socket.hpp>
|
#include <boost/asio/basic_stream_socket.hpp>
|
||||||
#include <boost/asio/coroutine.hpp>
|
#include <boost/asio/coroutine.hpp>
|
||||||
#include <boost/throw_exception.hpp>
|
#include <boost/throw_exception.hpp>
|
||||||
@ -73,18 +74,12 @@ public:
|
|||||||
std::size_t bytes_transferred,
|
std::size_t bytes_transferred,
|
||||||
bool cont = true)
|
bool cont = true)
|
||||||
{
|
{
|
||||||
std::size_t max_size;
|
|
||||||
std::size_t max_prepare;
|
std::size_t max_prepare;
|
||||||
BOOST_ASIO_CORO_REENTER(*this)
|
BOOST_ASIO_CORO_REENTER(*this)
|
||||||
{
|
{
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
max_size = cond_(ec, total_, b_);
|
max_prepare = beast::read_size(b_, cond_(ec, total_, b_));
|
||||||
max_prepare = std::min<std::size_t>(
|
|
||||||
std::max<std::size_t>(
|
|
||||||
512, b_.capacity() - b_.size()),
|
|
||||||
std::min<std::size_t>(
|
|
||||||
max_size, b_.max_size() - b_.size()));
|
|
||||||
if(max_prepare == 0)
|
if(max_prepare == 0)
|
||||||
break;
|
break;
|
||||||
BOOST_ASIO_CORO_YIELD
|
BOOST_ASIO_CORO_YIELD
|
||||||
@ -201,16 +196,10 @@ read(
|
|||||||
"CompletionCondition type requirements not met");
|
"CompletionCondition type requirements not met");
|
||||||
ec = {};
|
ec = {};
|
||||||
std::size_t total = 0;
|
std::size_t total = 0;
|
||||||
std::size_t max_size;
|
|
||||||
std::size_t max_prepare;
|
std::size_t max_prepare;
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
max_size = cond(ec, total, buffer);
|
max_prepare = beast::read_size(buffer, cond(ec, total, buffer));
|
||||||
max_prepare = std::min<std::size_t>(
|
|
||||||
std::max<std::size_t>(
|
|
||||||
512, buffer.capacity() - buffer.size()),
|
|
||||||
std::min<std::size_t>(
|
|
||||||
max_size, buffer.max_size() - buffer.size()));
|
|
||||||
if(max_prepare == 0)
|
if(max_prepare == 0)
|
||||||
break;
|
break;
|
||||||
std::size_t const bytes_transferred =
|
std::size_t const bytes_transferred =
|
||||||
|
@ -46,7 +46,6 @@ read_size(DynamicBuffer& buffer,
|
|||||||
static_assert(
|
static_assert(
|
||||||
net::is_dynamic_buffer<DynamicBuffer>::value,
|
net::is_dynamic_buffer<DynamicBuffer>::value,
|
||||||
"DynamicBuffer type requirements not met");
|
"DynamicBuffer type requirements not met");
|
||||||
BOOST_ASSERT(max_size >= 1);
|
|
||||||
auto const size = buffer.size();
|
auto const size = buffer.size();
|
||||||
auto const limit = buffer.max_size() - size;
|
auto const limit = buffer.max_size() - size;
|
||||||
BOOST_ASSERT(size <= buffer.max_size());
|
BOOST_ASSERT(size <= buffer.max_size());
|
||||||
|
Reference in New Issue
Block a user