Refactor read_size_helper

This commit is contained in:
Miguel Portilla
2016-10-18 16:23:23 -04:00
committed by Vinnie Falco
parent 753281959e
commit 0a1c24eb9f
2 changed files with 7 additions and 4 deletions

View File

@ -14,6 +14,7 @@
* Add headers_parser
* Engaged invokable is destructible
* Improve websocket example in README.md
* Refactor read_size_helper
API Changes:

View File

@ -856,10 +856,12 @@ read_size_helper(basic_streambuf<
Allocator> const& streambuf, std::size_t max_size)
{
auto const avail = streambuf.capacity() - streambuf.size();
if(avail == 0)
return std::min(max_size,
std::max<std::size_t>(512, streambuf.alloc_size_));
return std::min(max_size, avail);
if (avail > 0)
return std::min(avail, max_size);
constexpr std::size_t low = 512;
if (streambuf.alloc_size_ > low)
return std::min(max_size, streambuf.alloc_size_);
return std::min(max_size, low);
}
template<class Alloc, class T>