2 // Copyright (c) 2016-2017 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/beast/core/type_traits.hpp>
15 #include <boost/throw_exception.hpp>
20 /** Returns a natural read size.
22 This function inspects the capacity, size, and maximum
23 size of the dynamic buffer. Then it computes a natural
24 read size given the passed-in upper limit. It favors
25 a read size that does not require a reallocation, subject
26 to a reasonable minimum to avoid tiny reads.
28 @param buffer The dynamic buffer to inspect.
30 @param max_size An upper limit on the returned value.
32 @note If the buffer is already at its maximum size, zero
35 template<class DynamicBuffer>
37 read_size(DynamicBuffer& buffer, std::size_t max_size);
39 /** Returns a natural read size or throw if the buffer is full.
41 This function inspects the capacity, size, and maximum
42 size of the dynamic buffer. Then it computes a natural
43 read size given the passed-in upper limit. It favors
44 a read size that does not require a reallocation, subject
45 to a reasonable minimum to avoid tiny reads.
47 @param buffer The dynamic buffer to inspect.
49 @param max_size An upper limit on the returned value.
51 @throws std::length_error if `max_size > 0` and the buffer
54 template<class DynamicBuffer>
56 read_size_or_throw(DynamicBuffer& buffer,
57 std::size_t max_size);
62 #include <boost/beast/core/impl/read_size.ipp>