Rename prepare_buffer(s) to buffer_prefix (API Change)

This commit is contained in:
Vinnie Falco
2017-05-14 08:23:37 -07:00
parent 83ea2308a2
commit 68a0f3af4f
17 changed files with 95 additions and 94 deletions

View File

@ -14,7 +14,7 @@ API Changes
* Return http::error::end_of_stream on HTTP read eof * Return http::error::end_of_stream on HTTP read eof
* Remove placeholders * Remove placeholders
* Move prepare_buffers to prepare_buffer.hpp * Move prepare_buffers to prepare_buffer.hpp
* Replace asynchronous helper macros with template aliases * Rename prepare_buffer(s) to buffer_prefix
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -189,12 +189,11 @@ underlying memory, whose lifetime is retained by the caller.
increments of a buffer sequence. increments of a buffer sequence.
]] ]]
[[ [[
[link beast.ref.prepare_buffer `prepare_buffer`] [link beast.ref.buffer_prefix `buffer_prefix`]
[link beast.ref.prepare_buffers `prepare_buffers`]
][ ][
These functions return a new buffer sequence which wraps the underlying This function returns a new buffer or buffer sequence which wraps the
memory of an existing buffer sequence, but with a smaller size. This underlying memory of an existing buffer sequence, but with a smaller size.
lets callers work with a prefix of a buffer sequence. This lets callers work with a prefix of a buffer sequence.
]] ]]
] ]

View File

@ -179,10 +179,9 @@
<simplelist type="vert" columns="1"> <simplelist type="vert" columns="1">
<member><link linkend="beast.ref.bind_handler">bind_handler</link></member> <member><link linkend="beast.ref.bind_handler">bind_handler</link></member>
<member><link linkend="beast.ref.buffer_cat">buffer_cat</link></member> <member><link linkend="beast.ref.buffer_cat">buffer_cat</link></member>
<member><link linkend="beast.ref.buffer_prefix">buffer_prefix</link></member>
<member><link linkend="beast.ref.buffers">buffers</link></member> <member><link linkend="beast.ref.buffers">buffers</link></member>
<member><link linkend="beast.ref.ostream">ostream</link></member> <member><link linkend="beast.ref.ostream">ostream</link></member>
<member><link linkend="beast.ref.prepare_buffer">prepare_buffer</link></member>
<member><link linkend="beast.ref.prepare_buffers">prepare_buffers</link></member>
<member><link linkend="beast.ref.system_category">system_category</link></member> <member><link linkend="beast.ref.system_category">system_category</link></member>
<member><link linkend="beast.ref.to_static_string">to_static_string</link></member> <member><link linkend="beast.ref.to_static_string">to_static_string</link></member>
</simplelist> </simplelist>

View File

@ -10,8 +10,8 @@
#include <beast/core/async_result.hpp> #include <beast/core/async_result.hpp>
#include <beast/core/bind_handler.hpp> #include <beast/core/bind_handler.hpp>
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/error.hpp> #include <beast/core/error.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/websocket/teardown.hpp> #include <beast/websocket/teardown.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
@ -69,7 +69,7 @@ public:
error_code& ec) error_code& ec)
{ {
auto const n = boost::asio::buffer_copy( auto const n = boost::asio::buffer_copy(
buffers, prepare_buffer(read_max_, cb_)); buffers, buffer_prefix(read_max_, cb_));
if(n > 0) if(n > 0)
cb_ = cb_ + n; cb_ = cb_ + n;
else else

View File

@ -10,8 +10,8 @@
#include <beast/core/async_result.hpp> #include <beast/core/async_result.hpp>
#include <beast/core/bind_handler.hpp> #include <beast/core/bind_handler.hpp>
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/error.hpp> #include <beast/core/error.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/websocket/teardown.hpp> #include <beast/websocket/teardown.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
@ -67,7 +67,7 @@ public:
error_code& ec) error_code& ec)
{ {
auto const n = boost::asio::buffer_copy( auto const n = boost::asio::buffer_copy(
buffers, prepare_buffer(read_max_, cb_)); buffers, buffer_prefix(read_max_, cb_));
if(n > 0) if(n > 0)
cb_ = cb_ + n; cb_ = cb_ + n;
else else

View File

@ -13,6 +13,7 @@
#include <beast/core/async_result.hpp> #include <beast/core/async_result.hpp>
#include <beast/core/bind_handler.hpp> #include <beast/core/bind_handler.hpp>
#include <beast/core/buffer_cat.hpp> #include <beast/core/buffer_cat.hpp>
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/buffers_adapter.hpp> #include <beast/core/buffers_adapter.hpp>
#include <beast/core/consuming_buffers.hpp> #include <beast/core/consuming_buffers.hpp>
#include <beast/core/buffered_read_stream.hpp> #include <beast/core/buffered_read_stream.hpp>
@ -23,7 +24,6 @@
#include <beast/core/handler_ptr.hpp> #include <beast/core/handler_ptr.hpp>
#include <beast/core/multi_buffer.hpp> #include <beast/core/multi_buffer.hpp>
#include <beast/core/ostream.hpp> #include <beast/core/ostream.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/core/static_buffer.hpp> #include <beast/core/static_buffer.hpp>
#include <beast/core/static_string.hpp> #include <beast/core/static_string.hpp>
#include <beast/core/type_traits.hpp> #include <beast/core/type_traits.hpp>

View File

@ -5,22 +5,19 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// //
#ifndef BEAST_PREPARE_BUFFER_HPP #ifndef BEAST_BUFFER_PREFIX_HPP
#define BEAST_PREPARE_BUFFER_HPP #define BEAST_BUFFER_PREFIX_HPP
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/core/detail/prepare_buffer.hpp> #include <beast/core/type_traits.hpp>
#include <beast/core/detail/buffer_prefix.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <algorithm>
#include <cstdint> #include <cstdint>
#include <iterator>
#include <stdexcept>
#include <type_traits> #include <type_traits>
#include <utility>
namespace beast { namespace beast {
/** Return a shortened buffer. /** Returns a prefix of a constant buffer sequence.
The returned buffer points to the same memory as the The returned buffer points to the same memory as the
passed buffer, but with a size that is equal to or less passed buffer, but with a size that is equal to or less
@ -36,7 +33,7 @@ namespace beast {
*/ */
inline inline
boost::asio::const_buffer boost::asio::const_buffer
prepare_buffer(std::size_t n, buffer_prefix(std::size_t n,
boost::asio::const_buffer buffer) boost::asio::const_buffer buffer)
{ {
using boost::asio::buffer_cast; using boost::asio::buffer_cast;
@ -45,7 +42,7 @@ prepare_buffer(std::size_t n,
(std::min)(n, buffer_size(buffer)) }; (std::min)(n, buffer_size(buffer)) };
} }
/** Return a shortened buffer. /** Returns a prefix of a mutable buffer sequence.
The returned buffer points to the same memory as the The returned buffer points to the same memory as the
passed buffer, but with a size that is equal to or less passed buffer, but with a size that is equal to or less
@ -61,7 +58,7 @@ prepare_buffer(std::size_t n,
*/ */
inline inline
boost::asio::mutable_buffer boost::asio::mutable_buffer
prepare_buffer(std::size_t n, buffer_prefix(std::size_t n,
boost::asio::mutable_buffer buffer) boost::asio::mutable_buffer buffer)
{ {
using boost::asio::buffer_cast; using boost::asio::buffer_cast;
@ -70,32 +67,38 @@ prepare_buffer(std::size_t n,
(std::min)(n, buffer_size(buffer)) }; (std::min)(n, buffer_size(buffer)) };
} }
/** Return a shortened buffer sequence. /** Returns a prefix of a buffer sequence.
This function returns a new buffer sequence which adapts the This function returns a new buffer sequence which when iterated,
passed buffer sequence and efficiently presents a shorter subset presents a shorter subset of the original list of buffers starting
of the original list of buffers starting with the first byte of with the first byte of the original sequence.
the original sequence.
@param n The maximum number of bytes in the wrapped @param n The maximum number of bytes in the wrapped
sequence. If this is larger than the size of passed, sequence. If this is larger than the size of passed,
buffers, the resulting sequence will represent the buffers, the resulting sequence will represent the
entire input sequence. entire input sequence.
@param buffers The buffer sequence to adapt. A copy of @param buffers An instance of @b ConstBufferSequence or
the sequence will be made, but ownership of the underlying @MutableBufferSequence to adapt. A copy of the sequence
memory is not transferred. will be made, but ownership of the underlying memory is
not transferred.
*/ */
template<class BufferSequence> template<class BufferSequence>
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
implementation_defined implementation_defined
#else #else
inline inline
detail::prepare_buffers_helper<BufferSequence> typename std::enable_if<
! std::is_convertible<BufferSequence, boost::asio::const_buffer>::value,
detail::buffer_prefix_helper<BufferSequence>>::type
#endif #endif
prepare_buffers(std::size_t n, BufferSequence const& buffers) buffer_prefix(std::size_t n, BufferSequence const& buffers)
{ {
return detail::prepare_buffers_helper<BufferSequence>(n, buffers); static_assert(
is_const_buffer_sequence<BufferSequence>::value ||
is_mutable_buffer_sequence<BufferSequence>::value,
"BufferSequence requirements not met");
return detail::buffer_prefix_helper<BufferSequence>(n, buffers);
} }
} // beast } // beast

View File

@ -62,11 +62,11 @@ namespace beast {
boost::asio::read_until( boost::asio::read_until(
stream.next_layer(), stream.buffer(), "\r\n\r\n"); stream.next_layer(), stream.buffer(), "\r\n\r\n");
// Use prepare_buffers() to limit the input // Use buffer_prefix() to limit the input
// sequence to only the data up to and including // sequence to only the data up to and including
// the trailing "\r\n\r\n". // the trailing "\r\n\r\n".
// //
auto header_buffers = prepare_buffers( auto header_buffers = buffer_prefix(
bytes_transferred, stream.buffer().data()); bytes_transferred, stream.buffer().data());
... ...

View File

@ -21,7 +21,7 @@ namespace detail {
inline inline
boost::asio::const_buffer boost::asio::const_buffer
prepare_buffer(std::size_t n, buffer_prefix(std::size_t n,
boost::asio::const_buffer buffer) boost::asio::const_buffer buffer)
{ {
using boost::asio::buffer_cast; using boost::asio::buffer_cast;
@ -32,7 +32,7 @@ prepare_buffer(std::size_t n,
inline inline
boost::asio::mutable_buffer boost::asio::mutable_buffer
prepare_buffer(std::size_t n, buffer_prefix(std::size_t n,
boost::asio::mutable_buffer buffer) boost::asio::mutable_buffer buffer)
{ {
using boost::asio::buffer_cast; using boost::asio::buffer_cast;
@ -50,7 +50,7 @@ prepare_buffer(std::size_t n,
@tparam BufferSequence The buffer sequence to adapt. @tparam BufferSequence The buffer sequence to adapt.
*/ */
template<class BufferSequence> template<class BufferSequence>
class prepare_buffers_helper class buffer_prefix_helper
{ {
using iter_type = using iter_type =
typename BufferSequence::const_iterator; typename BufferSequence::const_iterator;
@ -61,7 +61,7 @@ class prepare_buffers_helper
std::size_t size_; std::size_t size_;
template<class Deduced> template<class Deduced>
prepare_buffers_helper(Deduced&& other, buffer_prefix_helper(Deduced&& other,
std::size_t nback, std::size_t nend) std::size_t nback, std::size_t nend)
: bs_(std::forward<Deduced>(other).bs_) : bs_(std::forward<Deduced>(other).bs_)
, back_(std::next(bs_.begin(), nback)) , back_(std::next(bs_.begin(), nback))
@ -92,16 +92,16 @@ public:
#endif #endif
/// Move constructor. /// Move constructor.
prepare_buffers_helper(prepare_buffers_helper&&); buffer_prefix_helper(buffer_prefix_helper&&);
/// Copy constructor. /// Copy constructor.
prepare_buffers_helper(prepare_buffers_helper const&); buffer_prefix_helper(buffer_prefix_helper const&);
/// Move assignment. /// Move assignment.
prepare_buffers_helper& operator=(prepare_buffers_helper&&); buffer_prefix_helper& operator=(buffer_prefix_helper&&);
/// Copy assignment. /// Copy assignment.
prepare_buffers_helper& operator=(prepare_buffers_helper const&); buffer_prefix_helper& operator=(buffer_prefix_helper const&);
/** Construct a shortened buffer sequence. /** Construct a shortened buffer sequence.
@ -114,7 +114,7 @@ public:
the sequence will be made, but ownership of the underlying the sequence will be made, but ownership of the underlying
memory is not transferred. memory is not transferred.
*/ */
prepare_buffers_helper(std::size_t n, BufferSequence const& buffers); buffer_prefix_helper(std::size_t n, BufferSequence const& buffers);
/// Get a bidirectional iterator to the first element. /// Get a bidirectional iterator to the first element.
const_iterator const_iterator
@ -126,14 +126,14 @@ public:
}; };
template<class BufferSequence> template<class BufferSequence>
class prepare_buffers_helper<BufferSequence>::const_iterator class buffer_prefix_helper<BufferSequence>::const_iterator
{ {
friend class prepare_buffers_helper<BufferSequence>; friend class buffer_prefix_helper<BufferSequence>;
using iter_type = using iter_type =
typename BufferSequence::const_iterator; typename BufferSequence::const_iterator;
prepare_buffers_helper const* b_ = nullptr; buffer_prefix_helper const* b_ = nullptr;
typename BufferSequence::const_iterator it_; typename BufferSequence::const_iterator it_;
public: public:
@ -171,7 +171,7 @@ public:
operator*() const operator*() const
{ {
if(it_ == b_->back_) if(it_ == b_->back_)
return prepare_buffer(b_->size_, *it_); return buffer_prefix(b_->size_, *it_);
return *it_; return *it_;
} }
@ -209,7 +209,7 @@ public:
} }
private: private:
const_iterator(prepare_buffers_helper const& b, const_iterator(buffer_prefix_helper const& b,
bool at_end) bool at_end)
: b_(&b) : b_(&b)
, it_(at_end ? b.end_ : b.bs_.begin()) , it_(at_end ? b.end_ : b.bs_.begin())
@ -219,7 +219,7 @@ private:
template<class BufferSequence> template<class BufferSequence>
void void
prepare_buffers_helper<BufferSequence>:: buffer_prefix_helper<BufferSequence>::
setup(std::size_t n) setup(std::size_t n)
{ {
for(end_ = bs_.begin(); end_ != bs_.end(); ++end_) for(end_ = bs_.begin(); end_ != bs_.end(); ++end_)
@ -239,7 +239,7 @@ setup(std::size_t n)
} }
template<class BufferSequence> template<class BufferSequence>
prepare_buffers_helper<BufferSequence>::const_iterator:: buffer_prefix_helper<BufferSequence>::const_iterator::
const_iterator(const_iterator&& other) const_iterator(const_iterator&& other)
: b_(other.b_) : b_(other.b_)
, it_(std::move(other.it_)) , it_(std::move(other.it_))
@ -247,7 +247,7 @@ const_iterator(const_iterator&& other)
} }
template<class BufferSequence> template<class BufferSequence>
prepare_buffers_helper<BufferSequence>::const_iterator:: buffer_prefix_helper<BufferSequence>::const_iterator::
const_iterator(const_iterator const& other) const_iterator(const_iterator const& other)
: b_(other.b_) : b_(other.b_)
, it_(other.it_) , it_(other.it_)
@ -256,7 +256,7 @@ const_iterator(const_iterator const& other)
template<class BufferSequence> template<class BufferSequence>
auto auto
prepare_buffers_helper<BufferSequence>::const_iterator:: buffer_prefix_helper<BufferSequence>::const_iterator::
operator=(const_iterator&& other) -> operator=(const_iterator&& other) ->
const_iterator& const_iterator&
{ {
@ -267,7 +267,7 @@ operator=(const_iterator&& other) ->
template<class BufferSequence> template<class BufferSequence>
auto auto
prepare_buffers_helper<BufferSequence>::const_iterator:: buffer_prefix_helper<BufferSequence>::const_iterator::
operator=(const_iterator const& other) -> operator=(const_iterator const& other) ->
const_iterator& const_iterator&
{ {
@ -279,18 +279,18 @@ operator=(const_iterator const& other) ->
} }
template<class BufferSequence> template<class BufferSequence>
prepare_buffers_helper<BufferSequence>:: buffer_prefix_helper<BufferSequence>::
prepare_buffers_helper(prepare_buffers_helper&& other) buffer_prefix_helper(buffer_prefix_helper&& other)
: prepare_buffers_helper(std::move(other), : buffer_prefix_helper(std::move(other),
std::distance<iter_type>(other.bs_.begin(), other.back_), std::distance<iter_type>(other.bs_.begin(), other.back_),
std::distance<iter_type>(other.bs_.begin(), other.end_)) std::distance<iter_type>(other.bs_.begin(), other.end_))
{ {
} }
template<class BufferSequence> template<class BufferSequence>
prepare_buffers_helper<BufferSequence>:: buffer_prefix_helper<BufferSequence>::
prepare_buffers_helper(prepare_buffers_helper const& other) buffer_prefix_helper(buffer_prefix_helper const& other)
: prepare_buffers_helper(other, : buffer_prefix_helper(other,
std::distance<iter_type>(other.bs_.begin(), other.back_), std::distance<iter_type>(other.bs_.begin(), other.back_),
std::distance<iter_type>(other.bs_.begin(), other.end_)) std::distance<iter_type>(other.bs_.begin(), other.end_))
{ {
@ -298,9 +298,9 @@ prepare_buffers_helper(prepare_buffers_helper const& other)
template<class BufferSequence> template<class BufferSequence>
auto auto
prepare_buffers_helper<BufferSequence>:: buffer_prefix_helper<BufferSequence>::
operator=(prepare_buffers_helper&& other) -> operator=(buffer_prefix_helper&& other) ->
prepare_buffers_helper& buffer_prefix_helper&
{ {
auto const nback = std::distance<iter_type>( auto const nback = std::distance<iter_type>(
other.bs_.begin(), other.back_); other.bs_.begin(), other.back_);
@ -315,9 +315,9 @@ operator=(prepare_buffers_helper&& other) ->
template<class BufferSequence> template<class BufferSequence>
auto auto
prepare_buffers_helper<BufferSequence>:: buffer_prefix_helper<BufferSequence>::
operator=(prepare_buffers_helper const& other) -> operator=(buffer_prefix_helper const& other) ->
prepare_buffers_helper& buffer_prefix_helper&
{ {
auto const nback = std::distance<iter_type>( auto const nback = std::distance<iter_type>(
other.bs_.begin(), other.back_); other.bs_.begin(), other.back_);
@ -331,8 +331,8 @@ operator=(prepare_buffers_helper const& other) ->
} }
template<class BufferSequence> template<class BufferSequence>
prepare_buffers_helper<BufferSequence>:: buffer_prefix_helper<BufferSequence>::
prepare_buffers_helper(std::size_t n, BufferSequence const& bs) buffer_prefix_helper(std::size_t n, BufferSequence const& bs)
: bs_(bs) : bs_(bs)
{ {
setup(n); setup(n);
@ -341,7 +341,7 @@ prepare_buffers_helper(std::size_t n, BufferSequence const& bs)
template<class BufferSequence> template<class BufferSequence>
inline inline
auto auto
prepare_buffers_helper<BufferSequence>::begin() const -> buffer_prefix_helper<BufferSequence>::begin() const ->
const_iterator const_iterator
{ {
return const_iterator{*this, false}; return const_iterator{*this, false};
@ -350,7 +350,7 @@ prepare_buffers_helper<BufferSequence>::begin() const ->
template<class BufferSequence> template<class BufferSequence>
inline inline
auto auto
prepare_buffers_helper<BufferSequence>::end() const -> buffer_prefix_helper<BufferSequence>::end() const ->
const_iterator const_iterator
{ {
return const_iterator{*this, true}; return const_iterator{*this, true};

View File

@ -14,9 +14,9 @@
#include <beast/http/read.hpp> #include <beast/http/read.hpp>
#include <beast/http/string_body.hpp> #include <beast/http/string_body.hpp>
#include <beast/http/write.hpp> #include <beast/http/write.hpp>
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/handler_helpers.hpp> #include <beast/core/handler_helpers.hpp>
#include <beast/core/handler_ptr.hpp> #include <beast/core/handler_ptr.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <memory> #include <memory>

View File

@ -9,9 +9,9 @@
#define BEAST_WEBSOCKET_IMPL_READ_IPP #define BEAST_WEBSOCKET_IMPL_READ_IPP
#include <beast/websocket/teardown.hpp> #include <beast/websocket/teardown.hpp>
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/handler_helpers.hpp> #include <beast/core/handler_helpers.hpp>
#include <beast/core/handler_ptr.hpp> #include <beast/core/handler_ptr.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/core/static_buffer.hpp> #include <beast/core/static_buffer.hpp>
#include <beast/core/type_traits.hpp> #include <beast/core/type_traits.hpp>
#include <beast/core/detail/clamp.hpp> #include <beast/core/detail/clamp.hpp>
@ -228,7 +228,7 @@ operator()(error_code ec,
case do_read_payload + 2: case do_read_payload + 2:
{ {
d.remain -= bytes_transferred; d.remain -= bytes_transferred;
auto const pb = prepare_buffers( auto const pb = buffer_prefix(
bytes_transferred, *d.dmb); bytes_transferred, *d.dmb);
if(d.fh.mask) if(d.fh.mask)
detail::mask_inplace(pb, d.key); detail::mask_inplace(pb, d.key);
@ -864,7 +864,7 @@ read_frame(frame_info& fi, DynamicBuffer& dynabuf, error_code& ec)
return; return;
BOOST_ASSERT(bytes_transferred > 0); BOOST_ASSERT(bytes_transferred > 0);
remain -= bytes_transferred; remain -= bytes_transferred;
auto const pb = prepare_buffers( auto const pb = buffer_prefix(
bytes_transferred, b); bytes_transferred, b);
if(fh.mask) if(fh.mask)
detail::mask_inplace(pb, key); detail::mask_inplace(pb, key);

View File

@ -16,8 +16,8 @@
#include <beast/http/write.hpp> #include <beast/http/write.hpp>
#include <beast/http/rfc7230.hpp> #include <beast/http/rfc7230.hpp>
#include <beast/core/buffer_cat.hpp> #include <beast/core/buffer_cat.hpp>
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/consuming_buffers.hpp> #include <beast/core/consuming_buffers.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/core/static_buffer.hpp> #include <beast/core/static_buffer.hpp>
#include <beast/core/type_traits.hpp> #include <beast/core/type_traits.hpp>
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>

View File

@ -10,10 +10,10 @@
#include <beast/core/bind_handler.hpp> #include <beast/core/bind_handler.hpp>
#include <beast/core/buffer_cat.hpp> #include <beast/core/buffer_cat.hpp>
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/consuming_buffers.hpp> #include <beast/core/consuming_buffers.hpp>
#include <beast/core/handler_helpers.hpp> #include <beast/core/handler_helpers.hpp>
#include <beast/core/handler_ptr.hpp> #include <beast/core/handler_ptr.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/core/static_buffer.hpp> #include <beast/core/static_buffer.hpp>
#include <beast/core/type_traits.hpp> #include <beast/core/type_traits.hpp>
#include <beast/core/detail/clamp.hpp> #include <beast/core/detail/clamp.hpp>
@ -267,7 +267,7 @@ operator()(error_code ec,
do_upcall : do_nomask_frag + 2; do_upcall : do_nomask_frag + 2;
boost::asio::async_write(d.ws.stream_, boost::asio::async_write(d.ws.stream_,
buffer_cat(d.fh_buf.data(), buffer_cat(d.fh_buf.data(),
prepare_buffers(n, d.cb)), buffer_prefix(n, d.cb)),
std::move(*this)); std::move(*this));
return; return;
} }
@ -698,7 +698,7 @@ write_frame(bool fin,
wr_.cont = ! fin; wr_.cont = ! fin;
boost::asio::write(stream_, boost::asio::write(stream_,
buffer_cat(fh_buf.data(), buffer_cat(fh_buf.data(),
prepare_buffers(n, cb)), ec); buffer_prefix(n, cb)), ec);
failed_ = ec != 0; failed_ = ec != 0;
if(failed_) if(failed_)
return; return;
@ -879,7 +879,7 @@ operator()(error_code ec, bool again)
auto const fin = d.remain <= 0; auto const fin = d.remain <= 0;
if(fin) if(fin)
d.state = 99; d.state = 99;
auto const pb = prepare_buffers(n, d.cb); auto const pb = buffer_prefix(n, d.cb);
d.cb.consume(n); d.cb.consume(n);
d.ws.async_write_frame(fin, pb, std::move(*this)); d.ws.async_write_frame(fin, pb, std::move(*this));
return; return;

View File

@ -19,6 +19,7 @@ unit-test core-tests :
core/async_result.cpp core/async_result.cpp
core/bind_handler.cpp core/bind_handler.cpp
core/buffer_cat.cpp core/buffer_cat.cpp
core/buffer_prefix.cpp
core/buffered_read_stream.cpp core/buffered_read_stream.cpp
core/buffers_adapter.cpp core/buffers_adapter.cpp
core/clamp.cpp core/clamp.cpp
@ -29,7 +30,6 @@ unit-test core-tests :
core/handler_ptr.cpp core/handler_ptr.cpp
core/multi_buffer.cpp core/multi_buffer.cpp
core/ostream.cpp core/ostream.cpp
core/prepare_buffer.cpp
core/static_buffer.cpp core/static_buffer.cpp
core/static_string.cpp core/static_string.cpp
core/string_view.cpp core/string_view.cpp

View File

@ -12,6 +12,7 @@ add_executable (core-tests
async_result.cpp async_result.cpp
bind_handler.cpp bind_handler.cpp
buffer_cat.cpp buffer_cat.cpp
buffer_prefix.cpp
buffers_adapter.cpp buffers_adapter.cpp
clamp.cpp clamp.cpp
consuming_buffers.cpp consuming_buffers.cpp
@ -22,7 +23,6 @@ add_executable (core-tests
handler_ptr.cpp handler_ptr.cpp
multi_buffer.cpp multi_buffer.cpp
ostream.cpp ostream.cpp
prepare_buffer.cpp
static_buffer.cpp static_buffer.cpp
static_string.cpp static_string.cpp
string_view.cpp string_view.cpp

View File

@ -6,7 +6,7 @@
// //
// Test that header file is self-contained. // Test that header file is self-contained.
#include <beast/core/prepare_buffer.hpp> #include <beast/core/buffer_prefix.hpp>
#include <beast/core/consuming_buffers.hpp> #include <beast/core/consuming_buffers.hpp>
#include <beast/unit_test/suite.hpp> #include <beast/unit_test/suite.hpp>
@ -15,7 +15,7 @@
namespace beast { namespace beast {
class prepare_buffer_test : public beast::unit_test::suite class buffer_prefix_test : public beast::unit_test::suite
{ {
public: public:
template<class ConstBufferSequence> template<class ConstBufferSequence>
@ -100,14 +100,14 @@ public:
BufferType{&s[x+y], z}}}; BufferType{&s[x+y], z}}};
for(std::size_t i = 0; i <= s.size() + 1; ++i) for(std::size_t i = 0; i <= s.size() + 1; ++i)
{ {
auto pb = prepare_buffers(i, bs); auto pb = buffer_prefix(i, bs);
BEAST_EXPECT(to_string(pb) == s.substr(0, i)); BEAST_EXPECT(to_string(pb) == s.substr(0, i));
auto pb2 = pb; auto pb2 = pb;
BEAST_EXPECT(to_string(pb2) == to_string(pb)); BEAST_EXPECT(to_string(pb2) == to_string(pb));
pb = prepare_buffers(0, bs); pb = buffer_prefix(0, bs);
pb2 = pb; pb2 = pb;
BEAST_EXPECT(buffer_size(pb2) == 0); BEAST_EXPECT(buffer_size(pb2) == 0);
pb2 = prepare_buffers(i, bs); pb2 = buffer_prefix(i, bs);
BEAST_EXPECT(to_string(pb2) == s.substr(0, i)); BEAST_EXPECT(to_string(pb2) == s.substr(0, i));
} }
} }
@ -119,9 +119,9 @@ public:
using boost::asio::buffer_copy; using boost::asio::buffer_copy;
using boost::asio::buffer_size; using boost::asio::buffer_size;
using boost::asio::null_buffers; using boost::asio::null_buffers;
auto pb0 = prepare_buffers(0, null_buffers{}); auto pb0 = buffer_prefix(0, null_buffers{});
BEAST_EXPECT(buffer_size(pb0) == 0); BEAST_EXPECT(buffer_size(pb0) == 0);
auto pb1 = prepare_buffers(1, null_buffers{}); auto pb1 = buffer_prefix(1, null_buffers{});
BEAST_EXPECT(buffer_size(pb1) == 0); BEAST_EXPECT(buffer_size(pb1) == 0);
BEAST_EXPECT(buffer_copy(pb0, pb1) == 0); BEAST_EXPECT(buffer_copy(pb0, pb1) == 0);
@ -133,7 +133,7 @@ public:
BEAST_EXPECT(buffer_size(cb) == 0); BEAST_EXPECT(buffer_size(cb) == 0);
BEAST_EXPECT(buffer_copy(cb, pb1) == 0); BEAST_EXPECT(buffer_copy(cb, pb1) == 0);
auto pbc = prepare_buffers(2, cb); auto pbc = buffer_prefix(2, cb);
BEAST_EXPECT(buffer_size(pbc) == 0); BEAST_EXPECT(buffer_size(pbc) == 0);
BEAST_EXPECT(buffer_copy(pbc, cb) == 0); BEAST_EXPECT(buffer_copy(pbc, cb) == 0);
} }
@ -147,7 +147,7 @@ public:
const_buffer{&b[0], 1}, const_buffer{&b[0], 1},
const_buffer{&b[1], 1}, const_buffer{&b[1], 1},
const_buffer{&b[2], 1}}}; const_buffer{&b[2], 1}}};
auto pb = prepare_buffers(2, bs); auto pb = buffer_prefix(2, bs);
BEAST_EXPECT(bsize1(pb) == 2); BEAST_EXPECT(bsize1(pb) == 2);
BEAST_EXPECT(bsize2(pb) == 2); BEAST_EXPECT(bsize2(pb) == 2);
BEAST_EXPECT(bsize3(pb) == 2); BEAST_EXPECT(bsize3(pb) == 2);
@ -172,6 +172,6 @@ public:
} }
}; };
BEAST_DEFINE_TESTSUITE(prepare_buffer,core,beast); BEAST_DEFINE_TESTSUITE(buffer_prefix,core,beast);
} // beast } // beast

View File

@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// //
#include <beast/core/buffer_prefix.hpp>
#include <beast/core/flat_buffer.hpp> #include <beast/core/flat_buffer.hpp>
#include <beast/core/prepare_buffer.hpp>
#include <beast/http/chunk_encode.hpp> #include <beast/http/chunk_encode.hpp>
#include <beast/http/read.hpp> #include <beast/http/read.hpp>
#include <beast/http/write.hpp> #include <beast/http/write.hpp>