forked from boostorg/beast
Rename to buffer_bytes
This commit is contained in:
1 parent
6ccdcdf51d
commit
9f2b0ce1db
62 files changed
+206
-258
No files matched your search
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BOOST_BEAST_BUFFER_SIZE_HPP
|
||||
#define BOOST_BEAST_BUFFER_SIZE_HPP
|
||||
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
#include <boost/beast/core/buffer_traits.hpp>
|
||||
|
||||
#endif
|
||||
@@ -143,11 +143,11 @@ using buffers_iterator_type =
|
||||
|
||||
This function is designed as an easier-to-use replacement for
|
||||
`net::buffer_size`. It recognizes customization points found through
|
||||
argument-dependent lookup. The call `beast::buffer_size(b)` is
|
||||
argument-dependent lookup. The call `beast::buffer_bytes(b)` is
|
||||
equivalent to performing:
|
||||
@code
|
||||
using namespace net;
|
||||
buffer_size(b);
|
||||
buffer_bytes(b);
|
||||
@endcode
|
||||
In addition this handles types which are convertible to
|
||||
`net::const_buffer`; these are not handled by `net::buffer_size`.
|
||||
@@ -162,9 +162,9 @@ using buffers_iterator_type =
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
template<class Buffers>
|
||||
void
|
||||
buffer_size(Buffers const& buffers);
|
||||
buffer_bytes(Buffers const& buffers);
|
||||
#else
|
||||
BOOST_BEAST_INLINE_VARIABLE(buffer_size, detail::buffer_size_impl)
|
||||
BOOST_BEAST_INLINE_VARIABLE(buffer_bytes, detail::buffer_bytes_impl)
|
||||
#endif
|
||||
|
||||
} // beast
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
|
||||
#if ! BOOST_BEAST_DOXYGEN
|
||||
std::size_t
|
||||
buffer_size_impl() const noexcept
|
||||
buffer_bytes_impl() const noexcept
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace beast {
|
||||
void send(SyncWriteStream& stream, ConstBufferSequence const& buffers)
|
||||
{
|
||||
buffers_suffix<ConstBufferSequence> bs{buffers};
|
||||
while(buffer_size(bs) > 0)
|
||||
while(buffer_bytes(bs) > 0)
|
||||
bs.consume(stream.write_some(bs));
|
||||
}
|
||||
@endcode
|
||||
|
||||
@@ -49,7 +49,7 @@ buffers_to_string(ConstBufferSequence const& buffers)
|
||||
net::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
"ConstBufferSequence type requirements not met");
|
||||
std::string result;
|
||||
result.reserve(buffer_size(buffers));
|
||||
result.reserve(buffer_bytes(buffers));
|
||||
for(auto const buffer : buffers_range_ref(buffers))
|
||||
result.append(static_cast<char const*>(
|
||||
buffer.data()), buffer.size());
|
||||
|
||||
@@ -46,65 +46,35 @@ struct buffers_iterator_type_helper<
|
||||
|
||||
#endif
|
||||
|
||||
template<class T, class = void>
|
||||
struct has_buffer_size_impl : std::false_type
|
||||
struct buffer_bytes_impl
|
||||
{
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct has_buffer_size_impl<T, boost::void_t<
|
||||
decltype(std::declval<std::size_t&>() =
|
||||
std::declval<T const&>().buffer_size_impl())>>
|
||||
: std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
struct buffer_size_impl
|
||||
{
|
||||
template<
|
||||
class B,
|
||||
class = typename std::enable_if<
|
||||
std::is_convertible<
|
||||
B, net::const_buffer>::value>::type>
|
||||
std::size_t
|
||||
operator()(B const& b) const
|
||||
operator()(net::const_buffer b) const noexcept
|
||||
{
|
||||
return net::const_buffer(b).size();
|
||||
}
|
||||
|
||||
template<
|
||||
class B,
|
||||
class = typename std::enable_if<
|
||||
! std::is_convertible<
|
||||
B, net::const_buffer>::value>::type,
|
||||
class = typename std::enable_if<
|
||||
net::is_const_buffer_sequence<B>::value &&
|
||||
! has_buffer_size_impl<B>::value>::type>
|
||||
std::size_t
|
||||
operator()(B const& b) const
|
||||
operator()(net::mutable_buffer b) const noexcept
|
||||
{
|
||||
using net::buffer_size;
|
||||
return buffer_size(b);
|
||||
return net::mutable_buffer(b).size();
|
||||
}
|
||||
|
||||
template<
|
||||
class B,
|
||||
class = typename std::enable_if<
|
||||
! std::is_convertible<B, net::const_buffer>::value>::type,
|
||||
class = typename std::enable_if<
|
||||
net::is_const_buffer_sequence<B>::value>::type,
|
||||
class = typename std::enable_if<
|
||||
has_buffer_size_impl<B>::value>::type>
|
||||
net::is_const_buffer_sequence<B>::value>::type>
|
||||
std::size_t
|
||||
operator()(B const& b) const
|
||||
operator()(B const& b) const noexcept
|
||||
{
|
||||
return b.buffer_size_impl();
|
||||
using net::buffer_size;
|
||||
return buffer_size(b);
|
||||
}
|
||||
};
|
||||
|
||||
/** Return `true` if a buffer sequence is empty
|
||||
|
||||
This is sometimes faster than using @ref buffer_size
|
||||
This is sometimes faster than using @ref buffer_bytes
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
bool
|
||||
|
||||
@@ -46,14 +46,14 @@ public:
|
||||
auto last = net::buffer_sequence_end(buffers);
|
||||
if(first != last)
|
||||
{
|
||||
result.size = buffer_size(*first);
|
||||
result.size = buffer_bytes(*first);
|
||||
if(result.size < limit)
|
||||
{
|
||||
auto it = first;
|
||||
auto prev = first;
|
||||
while(++it != last)
|
||||
{
|
||||
auto const n = buffer_size(*it);
|
||||
auto const n = buffer_bytes(*it);
|
||||
if(result.size + n > limit)
|
||||
break;
|
||||
result.size += n;
|
||||
|
||||
@@ -401,7 +401,7 @@ buffers_adaptor(MutableBufferSequence const& bs)
|
||||
, max_size_(
|
||||
[&bs]
|
||||
{
|
||||
return buffer_size(bs);
|
||||
return buffer_bytes(bs);
|
||||
}())
|
||||
{
|
||||
}
|
||||
@@ -418,7 +418,7 @@ buffers_adaptor(
|
||||
, max_size_(
|
||||
[&]
|
||||
{
|
||||
return buffer_size(bs_);
|
||||
return buffer_bytes(bs_);
|
||||
}())
|
||||
{
|
||||
}
|
||||
@@ -501,14 +501,14 @@ prepare(std::size_t n) ->
|
||||
end_ = out_;
|
||||
if(end_ != net::buffer_sequence_end(bs_))
|
||||
{
|
||||
auto size = buffer_size(*end_) - out_pos_;
|
||||
auto size = buffer_bytes(*end_) - out_pos_;
|
||||
if(n > size)
|
||||
{
|
||||
n -= size;
|
||||
while(++end_ !=
|
||||
net::buffer_sequence_end(bs_))
|
||||
{
|
||||
size = buffer_size(*end_);
|
||||
size = buffer_bytes(*end_);
|
||||
if(n < size)
|
||||
{
|
||||
out_end_ = n;
|
||||
@@ -544,7 +544,7 @@ commit(std::size_t n) noexcept
|
||||
while(out_ != last)
|
||||
{
|
||||
auto const avail =
|
||||
buffer_size(*out_) - out_pos_;
|
||||
buffer_bytes(*out_) - out_pos_;
|
||||
if(n < avail)
|
||||
{
|
||||
out_pos_ += n;
|
||||
@@ -561,7 +561,7 @@ commit(std::size_t n) noexcept
|
||||
n, out_end_ - out_pos_);
|
||||
out_pos_ += n;
|
||||
in_size_ += n;
|
||||
if(out_pos_ == buffer_size(*out_))
|
||||
if(out_pos_ == buffer_bytes(*out_))
|
||||
{
|
||||
++out_;
|
||||
out_pos_ = 0;
|
||||
@@ -577,7 +577,7 @@ consume(std::size_t n) noexcept
|
||||
while(begin_ != out_)
|
||||
{
|
||||
auto const avail =
|
||||
buffer_size(*begin_) - in_pos_;
|
||||
buffer_bytes(*begin_) - in_pos_;
|
||||
if(n < avail)
|
||||
{
|
||||
in_size_ -= n;
|
||||
|
||||
@@ -150,7 +150,7 @@ setup(std::size_t size)
|
||||
auto const last = bs_.end();
|
||||
while(end_ != last)
|
||||
{
|
||||
auto const len = buffer_size(*end_++);
|
||||
auto const len = buffer_bytes(*end_++);
|
||||
if(len >= size)
|
||||
{
|
||||
size_ += size;
|
||||
@@ -282,12 +282,6 @@ public:
|
||||
std::forward<Args>(args)...))
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t
|
||||
buffer_size_impl() const noexcept
|
||||
{
|
||||
return this->size();
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -324,12 +318,6 @@ public:
|
||||
std::forward<Args>(args)...))
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t
|
||||
buffer_size_impl() const noexcept
|
||||
{
|
||||
return this->size();
|
||||
}
|
||||
};
|
||||
|
||||
} // beast
|
||||
|
||||
@@ -208,7 +208,7 @@ consume(std::size_t amount)
|
||||
for(;amount > 0 && begin_ != end; ++begin_)
|
||||
{
|
||||
auto const len =
|
||||
buffer_size(*begin_) - skip_;
|
||||
buffer_bytes(*begin_) - skip_;
|
||||
if(amount < len)
|
||||
{
|
||||
skip_ += amount;
|
||||
|
||||
@@ -196,7 +196,7 @@ public:
|
||||
const_iterator end() const noexcept;
|
||||
|
||||
std::size_t
|
||||
buffer_size() const noexcept
|
||||
buffer_bytes() const noexcept
|
||||
{
|
||||
return b_->size();
|
||||
}
|
||||
@@ -1242,7 +1242,7 @@ basic_multi_buffer<Allocator>::
|
||||
debug_check() const
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
BOOST_ASSERT(buffer_size(data()) == in_size_);
|
||||
BOOST_ASSERT(buffer_bytes(data()) == in_size_);
|
||||
if(list_.empty())
|
||||
{
|
||||
BOOST_ASSERT(in_pos_ == 0);
|
||||
|
||||
@@ -75,7 +75,7 @@ operator<<(std::ostream& os,
|
||||
print (ConstBufferSequence const& buffers)
|
||||
{
|
||||
std::cout <<
|
||||
"Buffer size: " << buffer_size(buffers) << " bytes\n"
|
||||
"Buffer size: " << buffer_bytes(buffers) << " bytes\n"
|
||||
"Buffer data: '" << make_printable(buffers) << "'\n";
|
||||
}
|
||||
@endcode
|
||||
|
||||
Reference in new issue
Block a user