File indexing completed on 2025-01-18 09:29:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_CORE_DETAIL_FLAT_STREAM_HPP
0011 #define BOOST_BEAST_CORE_DETAIL_FLAT_STREAM_HPP
0012
0013 #include <boost/beast/core/buffer_traits.hpp>
0014 #include <boost/asio/buffer.hpp>
0015 #include <cstdlib>
0016
0017 namespace boost {
0018 namespace beast {
0019 namespace detail {
0020
0021 class flat_stream_base
0022 {
0023 public:
0024
0025
0026 static std::size_t constexpr max_size = 16 * 1024;
0027
0028
0029 static std::size_t constexpr max_stack = 8 * 1024;
0030
0031 struct flatten_result
0032 {
0033 std::size_t size;
0034 bool flatten;
0035 };
0036
0037
0038 template<class BufferSequence>
0039 static
0040 flatten_result
0041 flatten(
0042 BufferSequence const& buffers, std::size_t limit)
0043 {
0044 flatten_result result{0, false};
0045 auto first = net::buffer_sequence_begin(buffers);
0046 auto last = net::buffer_sequence_end(buffers);
0047 if(first != last)
0048 {
0049 result.size = buffer_bytes(*first);
0050 if(result.size < limit)
0051 {
0052 auto it = first;
0053 auto prev = first;
0054 while(++it != last)
0055 {
0056 auto const n = buffer_bytes(*it);
0057 if(result.size + n > limit)
0058 break;
0059 result.size += n;
0060 prev = it;
0061 }
0062 result.flatten = prev != first;
0063 }
0064 }
0065 return result;
0066 }
0067 };
0068
0069 }
0070 }
0071 }
0072
0073 #endif