forked from boostorg/beast
static_buffer coverage
This commit is contained in:
@@ -44,9 +44,7 @@ read_size_helper(
|
||||
BOOST_ASSERT(max_size >= 1);
|
||||
auto const size = buffer.size();
|
||||
auto const limit = buffer.max_size() - size;
|
||||
if(limit <= 0)
|
||||
BOOST_THROW_EXCEPTION(std::length_error{
|
||||
"dynamic buffer overflow"});
|
||||
BOOST_ASSERT(size <= buffer.max_size());
|
||||
return std::min<std::size_t>(
|
||||
std::max<std::size_t>(512, buffer.capacity() - size),
|
||||
std::min<std::size_t>(max_size, limit));
|
||||
|
||||
@@ -76,7 +76,7 @@ prepare_impl(std::size_t n) ->
|
||||
auto const len = size();
|
||||
if(n > capacity() - len)
|
||||
BOOST_THROW_EXCEPTION(std::length_error{
|
||||
"static_buffer overflow"});
|
||||
"buffer overflow"});
|
||||
if(len > 0)
|
||||
std::memmove(begin_, in_, len);
|
||||
in_ = begin_;
|
||||
@@ -99,6 +99,31 @@ consume_impl(std::size_t n)
|
||||
in_ += n;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<std::size_t N>
|
||||
static_buffer_n<N>::
|
||||
static_buffer_n(static_buffer_n const& other)
|
||||
: static_buffer(buf_, N)
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
this->commit(buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
auto
|
||||
static_buffer_n<N>::
|
||||
operator=(static_buffer_n const& other) ->
|
||||
static_buffer_n<N>&
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
this->consume(this->size());
|
||||
this->commit(buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // beast
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include <beast/config.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
namespace beast {
|
||||
@@ -37,6 +39,9 @@ class static_buffer
|
||||
char* last_;
|
||||
char* end_;
|
||||
|
||||
static_buffer(static_buffer const& other) = delete;
|
||||
static_buffer& operator=(static_buffer const&) = delete;
|
||||
|
||||
public:
|
||||
/// The type used to represent the input sequence as a list of buffers.
|
||||
using const_buffers_type = boost::asio::const_buffers_1;
|
||||
@@ -44,12 +49,6 @@ public:
|
||||
/// The type used to represent the output sequence as a list of buffers.
|
||||
using mutable_buffers_type = boost::asio::mutable_buffers_1;
|
||||
|
||||
static_buffer(
|
||||
static_buffer const& other) noexcept = delete;
|
||||
|
||||
static_buffer& operator=(
|
||||
static_buffer const&) noexcept = delete;
|
||||
|
||||
/** Constructor.
|
||||
|
||||
This creates a dynamic buffer using the provided storage area.
|
||||
@@ -185,17 +184,31 @@ class static_buffer_n : public static_buffer
|
||||
char buf_[N];
|
||||
|
||||
public:
|
||||
/// Copy constructor (disallowed).
|
||||
static_buffer_n(static_buffer_n const&) = delete;
|
||||
/// Copy constructor
|
||||
static_buffer_n(static_buffer_n const&);
|
||||
|
||||
/// Copy assignment (disallowed).
|
||||
static_buffer_n& operator=(static_buffer_n const&) = delete;
|
||||
/// Copy assignment
|
||||
static_buffer_n& operator=(static_buffer_n const&);
|
||||
|
||||
/// Construct a static buffer.
|
||||
static_buffer_n()
|
||||
: static_buffer(buf_, N)
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the @ref static_buffer portion of this object
|
||||
static_buffer&
|
||||
base()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Returns the @ref static_buffer portion of this object
|
||||
static_buffer const&
|
||||
base() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
} // beast
|
||||
|
||||
Reference in New Issue
Block a user