2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_READ_SIZE_HELPER_HPP
11 #define BOOST_BEAST_READ_SIZE_HELPER_HPP
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/throw_exception.hpp>
19 /** Returns a natural read size.
21 This function inspects the capacity, size, and maximum
22 size of the dynamic buffer. Then it computes a natural
23 read size given the passed-in upper limit. It favors
24 a read size that does not require a reallocation, subject
25 to a reasonable minimum to avoid tiny reads.
27 @param buffer The dynamic buffer to inspect.
29 @param max_size An upper limit on the returned value.
31 @note If the buffer is already at its maximum size, zero
34 template<class DynamicBuffer>
36 read_size(DynamicBuffer& buffer, std::size_t max_size);
38 /** Returns a natural read size or throw if the buffer is full.
40 This function inspects the capacity, size, and maximum
41 size of the dynamic buffer. Then it computes a natural
42 read size given the passed-in upper limit. It favors
43 a read size that does not require a reallocation, subject
44 to a reasonable minimum to avoid tiny reads.
46 @param buffer The dynamic buffer to inspect.
48 @param max_size An upper limit on the returned value.
50 @throws std::length_error if `max_size > 0` and the buffer
53 template<class DynamicBuffer>
55 read_size_or_throw(DynamicBuffer& buffer,
56 std::size_t max_size);
61 #include <boost/beast/core/impl/read_size.hpp>