Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:24

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
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     // Largest buffer size we will flatten.
0025     // 16KB is the upper limit on reasonably sized HTTP messages.
0026     static std::size_t constexpr max_size = 16 * 1024;
0027 
0028     // Largest stack we will use to flatten
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     // calculates the flatten settings for a buffer sequence
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 } // detail
0070 } // beast
0071 } // boost
0072 
0073 #endif