diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1304f862..9e3adfd8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,7 @@ API Changes
* Return http::error::end_of_stream on HTTP read eof
* Remove placeholders
* Move prepare_buffers to prepare_buffer.hpp
-* Replace asynchronous helper macros with template aliases
+* Rename prepare_buffer(s) to buffer_prefix
--------------------------------------------------------------------------------
diff --git a/doc/core.qbk b/doc/core.qbk
index 45b6dec5..40cd6f93 100644
--- a/doc/core.qbk
+++ b/doc/core.qbk
@@ -189,12 +189,11 @@ underlying memory, whose lifetime is retained by the caller.
increments of a buffer sequence.
]]
[[
- [link beast.ref.prepare_buffer `prepare_buffer`]
- [link beast.ref.prepare_buffers `prepare_buffers`]
+ [link beast.ref.buffer_prefix `buffer_prefix`]
][
- These functions return a new buffer sequence which wraps the underlying
- memory of an existing buffer sequence, but with a smaller size. This
- lets callers work with a prefix of a buffer sequence.
+ This function returns a new buffer or buffer sequence which wraps the
+ underlying memory of an existing buffer sequence, but with a smaller size.
+ This lets callers work with a prefix of a buffer sequence.
]]
]
diff --git a/doc/quickref.xml b/doc/quickref.xml
index ad6de992..41d508f8 100644
--- a/doc/quickref.xml
+++ b/doc/quickref.xml
@@ -179,10 +179,9 @@
bind_handler
buffer_cat
+ buffer_prefix
buffers
ostream
- prepare_buffer
- prepare_buffers
system_category
to_static_string
diff --git a/extras/beast/test/string_iostream.hpp b/extras/beast/test/string_iostream.hpp
index d7c03008..98342f73 100644
--- a/extras/beast/test/string_iostream.hpp
+++ b/extras/beast/test/string_iostream.hpp
@@ -10,8 +10,8 @@
#include
#include
+#include
#include
-#include
#include
#include
#include
@@ -69,7 +69,7 @@ public:
error_code& ec)
{
auto const n = boost::asio::buffer_copy(
- buffers, prepare_buffer(read_max_, cb_));
+ buffers, buffer_prefix(read_max_, cb_));
if(n > 0)
cb_ = cb_ + n;
else
diff --git a/extras/beast/test/string_istream.hpp b/extras/beast/test/string_istream.hpp
index 0f030128..3c9352a1 100644
--- a/extras/beast/test/string_istream.hpp
+++ b/extras/beast/test/string_istream.hpp
@@ -10,8 +10,8 @@
#include
#include
+#include
#include
-#include
#include
#include
#include
@@ -67,7 +67,7 @@ public:
error_code& ec)
{
auto const n = boost::asio::buffer_copy(
- buffers, prepare_buffer(read_max_, cb_));
+ buffers, buffer_prefix(read_max_, cb_));
if(n > 0)
cb_ = cb_ + n;
else
diff --git a/include/beast/core.hpp b/include/beast/core.hpp
index ba7711c7..5770e6fa 100644
--- a/include/beast/core.hpp
+++ b/include/beast/core.hpp
@@ -13,6 +13,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -23,7 +24,6 @@
#include
#include
#include
-#include
#include
#include
#include
diff --git a/include/beast/core/prepare_buffer.hpp b/include/beast/core/buffer_prefix.hpp
similarity index 61%
rename from include/beast/core/prepare_buffer.hpp
rename to include/beast/core/buffer_prefix.hpp
index da442ca6..a89a7050 100644
--- a/include/beast/core/prepare_buffer.hpp
+++ b/include/beast/core/buffer_prefix.hpp
@@ -5,22 +5,19 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BEAST_PREPARE_BUFFER_HPP
-#define BEAST_PREPARE_BUFFER_HPP
+#ifndef BEAST_BUFFER_PREFIX_HPP
+#define BEAST_BUFFER_PREFIX_HPP
#include
-#include
+#include
+#include
#include
-#include
#include
-#include
-#include
#include
-#include
namespace beast {
-/** Return a shortened buffer.
+/** Returns a prefix of a constant buffer sequence.
The returned buffer points to the same memory as the
passed buffer, but with a size that is equal to or less
@@ -36,7 +33,7 @@ namespace beast {
*/
inline
boost::asio::const_buffer
-prepare_buffer(std::size_t n,
+buffer_prefix(std::size_t n,
boost::asio::const_buffer buffer)
{
using boost::asio::buffer_cast;
@@ -45,7 +42,7 @@ prepare_buffer(std::size_t n,
(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
passed buffer, but with a size that is equal to or less
@@ -61,7 +58,7 @@ prepare_buffer(std::size_t n,
*/
inline
boost::asio::mutable_buffer
-prepare_buffer(std::size_t n,
+buffer_prefix(std::size_t n,
boost::asio::mutable_buffer buffer)
{
using boost::asio::buffer_cast;
@@ -70,32 +67,38 @@ prepare_buffer(std::size_t n,
(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
- passed buffer sequence and efficiently presents a shorter subset
- of the original list of buffers starting with the first byte of
- the original sequence.
+ This function returns a new buffer sequence which when iterated,
+ presents a shorter subset of the original list of buffers starting
+ with the first byte of the original sequence.
@param n The maximum number of bytes in the wrapped
sequence. If this is larger than the size of passed,
buffers, the resulting sequence will represent the
entire input sequence.
- @param buffers The buffer sequence to adapt. A copy of
- the sequence will be made, but ownership of the underlying
- memory is not transferred.
+ @param buffers An instance of @b ConstBufferSequence or
+ @MutableBufferSequence to adapt. A copy of the sequence
+ will be made, but ownership of the underlying memory is
+ not transferred.
*/
template
#if BEAST_DOXYGEN
implementation_defined
#else
inline
-detail::prepare_buffers_helper
+typename std::enable_if<
+ ! std::is_convertible::value,
+ detail::buffer_prefix_helper>::type
#endif
-prepare_buffers(std::size_t n, BufferSequence const& buffers)
+buffer_prefix(std::size_t n, BufferSequence const& buffers)
{
- return detail::prepare_buffers_helper(n, buffers);
+ static_assert(
+ is_const_buffer_sequence::value ||
+ is_mutable_buffer_sequence::value,
+ "BufferSequence requirements not met");
+ return detail::buffer_prefix_helper(n, buffers);
}
} // beast
diff --git a/include/beast/core/buffered_read_stream.hpp b/include/beast/core/buffered_read_stream.hpp
index 2e2ff68d..9957e2df 100644
--- a/include/beast/core/buffered_read_stream.hpp
+++ b/include/beast/core/buffered_read_stream.hpp
@@ -62,11 +62,11 @@ namespace beast {
boost::asio::read_until(
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
// the trailing "\r\n\r\n".
//
- auto header_buffers = prepare_buffers(
+ auto header_buffers = buffer_prefix(
bytes_transferred, stream.buffer().data());
...
diff --git a/include/beast/core/detail/prepare_buffer.hpp b/include/beast/core/detail/buffer_prefix.hpp
similarity index 80%
rename from include/beast/core/detail/prepare_buffer.hpp
rename to include/beast/core/detail/buffer_prefix.hpp
index 90a07b3b..9ce74b20 100644
--- a/include/beast/core/detail/prepare_buffer.hpp
+++ b/include/beast/core/detail/buffer_prefix.hpp
@@ -21,7 +21,7 @@ namespace detail {
inline
boost::asio::const_buffer
-prepare_buffer(std::size_t n,
+buffer_prefix(std::size_t n,
boost::asio::const_buffer buffer)
{
using boost::asio::buffer_cast;
@@ -32,7 +32,7 @@ prepare_buffer(std::size_t n,
inline
boost::asio::mutable_buffer
-prepare_buffer(std::size_t n,
+buffer_prefix(std::size_t n,
boost::asio::mutable_buffer buffer)
{
using boost::asio::buffer_cast;
@@ -50,7 +50,7 @@ prepare_buffer(std::size_t n,
@tparam BufferSequence The buffer sequence to adapt.
*/
template
-class prepare_buffers_helper
+class buffer_prefix_helper
{
using iter_type =
typename BufferSequence::const_iterator;
@@ -61,7 +61,7 @@ class prepare_buffers_helper
std::size_t size_;
template
- prepare_buffers_helper(Deduced&& other,
+ buffer_prefix_helper(Deduced&& other,
std::size_t nback, std::size_t nend)
: bs_(std::forward(other).bs_)
, back_(std::next(bs_.begin(), nback))
@@ -92,16 +92,16 @@ public:
#endif
/// Move constructor.
- prepare_buffers_helper(prepare_buffers_helper&&);
+ buffer_prefix_helper(buffer_prefix_helper&&);
/// Copy constructor.
- prepare_buffers_helper(prepare_buffers_helper const&);
+ buffer_prefix_helper(buffer_prefix_helper const&);
/// Move assignment.
- prepare_buffers_helper& operator=(prepare_buffers_helper&&);
+ buffer_prefix_helper& operator=(buffer_prefix_helper&&);
/// Copy assignment.
- prepare_buffers_helper& operator=(prepare_buffers_helper const&);
+ buffer_prefix_helper& operator=(buffer_prefix_helper const&);
/** Construct a shortened buffer sequence.
@@ -114,7 +114,7 @@ public:
the sequence will be made, but ownership of the underlying
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.
const_iterator
@@ -126,14 +126,14 @@ public:
};
template
-class prepare_buffers_helper::const_iterator
+class buffer_prefix_helper::const_iterator
{
- friend class prepare_buffers_helper;
+ friend class buffer_prefix_helper;
using iter_type =
typename BufferSequence::const_iterator;
- prepare_buffers_helper const* b_ = nullptr;
+ buffer_prefix_helper const* b_ = nullptr;
typename BufferSequence::const_iterator it_;
public:
@@ -171,7 +171,7 @@ public:
operator*() const
{
if(it_ == b_->back_)
- return prepare_buffer(b_->size_, *it_);
+ return buffer_prefix(b_->size_, *it_);
return *it_;
}
@@ -209,7 +209,7 @@ public:
}
private:
- const_iterator(prepare_buffers_helper const& b,
+ const_iterator(buffer_prefix_helper const& b,
bool at_end)
: b_(&b)
, it_(at_end ? b.end_ : b.bs_.begin())
@@ -219,7 +219,7 @@ private:
template
void
-prepare_buffers_helper::
+buffer_prefix_helper::
setup(std::size_t n)
{
for(end_ = bs_.begin(); end_ != bs_.end(); ++end_)
@@ -239,7 +239,7 @@ setup(std::size_t n)
}
template
-prepare_buffers_helper::const_iterator::
+buffer_prefix_helper::const_iterator::
const_iterator(const_iterator&& other)
: b_(other.b_)
, it_(std::move(other.it_))
@@ -247,7 +247,7 @@ const_iterator(const_iterator&& other)
}
template
-prepare_buffers_helper::const_iterator::
+buffer_prefix_helper::const_iterator::
const_iterator(const_iterator const& other)
: b_(other.b_)
, it_(other.it_)
@@ -256,7 +256,7 @@ const_iterator(const_iterator const& other)
template
auto
-prepare_buffers_helper::const_iterator::
+buffer_prefix_helper::const_iterator::
operator=(const_iterator&& other) ->
const_iterator&
{
@@ -267,7 +267,7 @@ operator=(const_iterator&& other) ->
template
auto
-prepare_buffers_helper::const_iterator::
+buffer_prefix_helper::const_iterator::
operator=(const_iterator const& other) ->
const_iterator&
{
@@ -279,18 +279,18 @@ operator=(const_iterator const& other) ->
}
template
-prepare_buffers_helper::
-prepare_buffers_helper(prepare_buffers_helper&& other)
- : prepare_buffers_helper(std::move(other),
+buffer_prefix_helper::
+buffer_prefix_helper(buffer_prefix_helper&& other)
+ : buffer_prefix_helper(std::move(other),
std::distance(other.bs_.begin(), other.back_),
std::distance(other.bs_.begin(), other.end_))
{
}
template
-prepare_buffers_helper::
-prepare_buffers_helper(prepare_buffers_helper const& other)
- : prepare_buffers_helper(other,
+buffer_prefix_helper::
+buffer_prefix_helper(buffer_prefix_helper const& other)
+ : buffer_prefix_helper(other,
std::distance(other.bs_.begin(), other.back_),
std::distance(other.bs_.begin(), other.end_))
{
@@ -298,9 +298,9 @@ prepare_buffers_helper(prepare_buffers_helper const& other)
template
auto
-prepare_buffers_helper::
-operator=(prepare_buffers_helper&& other) ->
- prepare_buffers_helper&
+buffer_prefix_helper::
+operator=(buffer_prefix_helper&& other) ->
+ buffer_prefix_helper&
{
auto const nback = std::distance(
other.bs_.begin(), other.back_);
@@ -315,9 +315,9 @@ operator=(prepare_buffers_helper&& other) ->
template
auto
-prepare_buffers_helper::
-operator=(prepare_buffers_helper const& other) ->
- prepare_buffers_helper&
+buffer_prefix_helper::
+operator=(buffer_prefix_helper const& other) ->
+ buffer_prefix_helper&
{
auto const nback = std::distance(
other.bs_.begin(), other.back_);
@@ -331,8 +331,8 @@ operator=(prepare_buffers_helper const& other) ->
}
template
-prepare_buffers_helper::
-prepare_buffers_helper(std::size_t n, BufferSequence const& bs)
+buffer_prefix_helper::
+buffer_prefix_helper(std::size_t n, BufferSequence const& bs)
: bs_(bs)
{
setup(n);
@@ -341,7 +341,7 @@ prepare_buffers_helper(std::size_t n, BufferSequence const& bs)
template
inline
auto
-prepare_buffers_helper::begin() const ->
+buffer_prefix_helper::begin() const ->
const_iterator
{
return const_iterator{*this, false};
@@ -350,7 +350,7 @@ prepare_buffers_helper::begin() const ->
template
inline
auto
-prepare_buffers_helper::end() const ->
+buffer_prefix_helper::end() const ->
const_iterator
{
return const_iterator{*this, true};
diff --git a/include/beast/websocket/impl/accept.ipp b/include/beast/websocket/impl/accept.ipp
index 8a6d4a50..f59703b6 100644
--- a/include/beast/websocket/impl/accept.ipp
+++ b/include/beast/websocket/impl/accept.ipp
@@ -14,9 +14,9 @@
#include
#include
#include
+#include
#include
#include
-#include
#include
#include
#include
diff --git a/include/beast/websocket/impl/read.ipp b/include/beast/websocket/impl/read.ipp
index 0a524425..5ea61448 100644
--- a/include/beast/websocket/impl/read.ipp
+++ b/include/beast/websocket/impl/read.ipp
@@ -9,9 +9,9 @@
#define BEAST_WEBSOCKET_IMPL_READ_IPP
#include
+#include
#include
#include
-#include
#include
#include
#include
@@ -228,7 +228,7 @@ operator()(error_code ec,
case do_read_payload + 2:
{
d.remain -= bytes_transferred;
- auto const pb = prepare_buffers(
+ auto const pb = buffer_prefix(
bytes_transferred, *d.dmb);
if(d.fh.mask)
detail::mask_inplace(pb, d.key);
@@ -864,7 +864,7 @@ read_frame(frame_info& fi, DynamicBuffer& dynabuf, error_code& ec)
return;
BOOST_ASSERT(bytes_transferred > 0);
remain -= bytes_transferred;
- auto const pb = prepare_buffers(
+ auto const pb = buffer_prefix(
bytes_transferred, b);
if(fh.mask)
detail::mask_inplace(pb, key);
diff --git a/include/beast/websocket/impl/stream.ipp b/include/beast/websocket/impl/stream.ipp
index 5bd14eb6..1eb420e7 100644
--- a/include/beast/websocket/impl/stream.ipp
+++ b/include/beast/websocket/impl/stream.ipp
@@ -16,8 +16,8 @@
#include
#include
#include
+#include
#include
-#include
#include
#include
#include
diff --git a/include/beast/websocket/impl/write.ipp b/include/beast/websocket/impl/write.ipp
index 97bf8581..7ead6bb2 100644
--- a/include/beast/websocket/impl/write.ipp
+++ b/include/beast/websocket/impl/write.ipp
@@ -10,10 +10,10 @@
#include
#include
+#include
#include
#include
#include
-#include
#include
#include
#include
@@ -267,7 +267,7 @@ operator()(error_code ec,
do_upcall : do_nomask_frag + 2;
boost::asio::async_write(d.ws.stream_,
buffer_cat(d.fh_buf.data(),
- prepare_buffers(n, d.cb)),
+ buffer_prefix(n, d.cb)),
std::move(*this));
return;
}
@@ -698,7 +698,7 @@ write_frame(bool fin,
wr_.cont = ! fin;
boost::asio::write(stream_,
buffer_cat(fh_buf.data(),
- prepare_buffers(n, cb)), ec);
+ buffer_prefix(n, cb)), ec);
failed_ = ec != 0;
if(failed_)
return;
@@ -879,7 +879,7 @@ operator()(error_code ec, bool again)
auto const fin = d.remain <= 0;
if(fin)
d.state = 99;
- auto const pb = prepare_buffers(n, d.cb);
+ auto const pb = buffer_prefix(n, d.cb);
d.cb.consume(n);
d.ws.async_write_frame(fin, pb, std::move(*this));
return;
diff --git a/test/Jamfile b/test/Jamfile
index 27d45218..badc7564 100644
--- a/test/Jamfile
+++ b/test/Jamfile
@@ -19,6 +19,7 @@ unit-test core-tests :
core/async_result.cpp
core/bind_handler.cpp
core/buffer_cat.cpp
+ core/buffer_prefix.cpp
core/buffered_read_stream.cpp
core/buffers_adapter.cpp
core/clamp.cpp
@@ -29,7 +30,6 @@ unit-test core-tests :
core/handler_ptr.cpp
core/multi_buffer.cpp
core/ostream.cpp
- core/prepare_buffer.cpp
core/static_buffer.cpp
core/static_string.cpp
core/string_view.cpp
diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt
index d442c35d..8a36adff 100644
--- a/test/core/CMakeLists.txt
+++ b/test/core/CMakeLists.txt
@@ -12,6 +12,7 @@ add_executable (core-tests
async_result.cpp
bind_handler.cpp
buffer_cat.cpp
+ buffer_prefix.cpp
buffers_adapter.cpp
clamp.cpp
consuming_buffers.cpp
@@ -22,7 +23,6 @@ add_executable (core-tests
handler_ptr.cpp
multi_buffer.cpp
ostream.cpp
- prepare_buffer.cpp
static_buffer.cpp
static_string.cpp
string_view.cpp
diff --git a/test/core/prepare_buffer.cpp b/test/core/buffer_prefix.cpp
similarity index 90%
rename from test/core/prepare_buffer.cpp
rename to test/core/buffer_prefix.cpp
index daa13994..83e68ebe 100644
--- a/test/core/prepare_buffer.cpp
+++ b/test/core/buffer_prefix.cpp
@@ -6,7 +6,7 @@
//
// Test that header file is self-contained.
-#include
+#include
#include
#include
@@ -15,7 +15,7 @@
namespace beast {
-class prepare_buffer_test : public beast::unit_test::suite
+class buffer_prefix_test : public beast::unit_test::suite
{
public:
template
@@ -100,14 +100,14 @@ public:
BufferType{&s[x+y], z}}};
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));
auto pb2 = pb;
BEAST_EXPECT(to_string(pb2) == to_string(pb));
- pb = prepare_buffers(0, bs);
+ pb = buffer_prefix(0, bs);
pb2 = pb;
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));
}
}
@@ -119,9 +119,9 @@ public:
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
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);
- auto pb1 = prepare_buffers(1, null_buffers{});
+ auto pb1 = buffer_prefix(1, null_buffers{});
BEAST_EXPECT(buffer_size(pb1) == 0);
BEAST_EXPECT(buffer_copy(pb0, pb1) == 0);
@@ -133,7 +133,7 @@ public:
BEAST_EXPECT(buffer_size(cb) == 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_copy(pbc, cb) == 0);
}
@@ -147,7 +147,7 @@ public:
const_buffer{&b[0], 1},
const_buffer{&b[1], 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(bsize2(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
diff --git a/test/http/design.cpp b/test/http/design.cpp
index 4407488a..25a139b0 100644
--- a/test/http/design.cpp
+++ b/test/http/design.cpp
@@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
+#include
#include
-#include
#include
#include
#include