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_CORE_DETAIL_FLAT_STREAM_HPP
11 #define BOOST_BEAST_CORE_DETAIL_FLAT_STREAM_HPP
13 #include <boost/beast/core/buffer_traits.hpp>
14 #include <boost/asio/buffer.hpp>
21 class flat_stream_base
24 // Largest buffer size we will flatten.
25 // 16KB is the upper limit on reasonably sized HTTP messages.
26 static std::size_t constexpr max_size = 16 * 1024;
28 // Largest stack we will use to flatten
29 static std::size_t constexpr max_stack = 8 * 1024;
37 // calculates the flatten settings for a buffer sequence
38 template<class BufferSequence>
42 BufferSequence const& buffers, std::size_t limit)
44 flatten_result result{0, false};
45 auto first = net::buffer_sequence_begin(buffers);
46 auto last = net::buffer_sequence_end(buffers);
49 result.size = buffer_bytes(*first);
50 if(result.size < limit)
56 auto const n = buffer_bytes(*it);
57 if(result.size + n > limit)
62 result.flatten = prev != first;