read_size.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  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)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_READ_SIZE_HELPER_HPP
  10. #define BOOST_BEAST_READ_SIZE_HELPER_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. #include <boost/throw_exception.hpp>
  13. namespace boost {
  14. namespace beast {
  15. /** Returns a natural read size.
  16. This function inspects the capacity, size, and maximum
  17. size of the dynamic buffer. Then it computes a natural
  18. read size given the passed-in upper limit. It favors
  19. a read size that does not require a reallocation, subject
  20. to a reasonable minimum to avoid tiny reads.
  21. @param buffer The dynamic buffer to inspect.
  22. @param max_size An upper limit on the returned value.
  23. @note If the buffer is already at its maximum size, zero
  24. is returned.
  25. */
  26. template<class DynamicBuffer>
  27. std::size_t
  28. read_size(DynamicBuffer& buffer, std::size_t max_size);
  29. /** Returns a natural read size or throw if the buffer is full.
  30. This function inspects the capacity, size, and maximum
  31. size of the dynamic buffer. Then it computes a natural
  32. read size given the passed-in upper limit. It favors
  33. a read size that does not require a reallocation, subject
  34. to a reasonable minimum to avoid tiny reads.
  35. @param buffer The dynamic buffer to inspect.
  36. @param max_size An upper limit on the returned value.
  37. @throws std::length_error if `max_size > 0` and the buffer
  38. is full.
  39. */
  40. template<class DynamicBuffer>
  41. std::size_t
  42. read_size_or_throw(DynamicBuffer& buffer,
  43. std::size_t max_size);
  44. } // beast
  45. } // boost
  46. #include <boost/beast/core/impl/read_size.hpp>
  47. #endif