diff --git a/CHANGELOG.md b/CHANGELOG.md index 807e71b0..300bcee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Improvements to code coverage * Use boost::lexical_cast instead of std::to_string * Fix prepare_buffers value_type +* Fix consuming_buffers value_type HTTP @@ -21,6 +22,7 @@ API Changes: * Refactor message and message_headers declarations * prepared_buffers is private +* consume_buffers is removed -------------------------------------------------------------------------------- diff --git a/doc/quickref.xml b/doc/quickref.xml index 4c03ca51..2f75e68a 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -177,7 +177,6 @@ bind_handler buffer_cat - consumed_buffers prepare_buffer prepare_buffers to_string diff --git a/include/beast/core/consuming_buffers.hpp b/include/beast/core/consuming_buffers.hpp index a467e171..87c3b841 100644 --- a/include/beast/core/consuming_buffers.hpp +++ b/include/beast/core/consuming_buffers.hpp @@ -37,20 +37,12 @@ namespace beast { consumable `ConstBufferSequence`. Violations of buffer const safety are not permitted, and will result in a compile error. */ -template +template class consuming_buffers { using iter_type = typename BufferSequence::const_iterator; - static_assert(is_BufferSequence::value, - "BufferSequence requirements not met"); - - static_assert(std::is_constructible::value_type>::value, - "ValueType requirements not met"); - BufferSequence bs_; iter_type begin_; std::size_t skip_ = 0; @@ -65,7 +57,12 @@ class consuming_buffers public: /// The type for each element in the list of buffers. - using value_type = ValueType; + using value_type = typename std::conditional< + std::is_convertible::value_type, + boost::asio::mutable_buffer>::value, + boost::asio::mutable_buffer, + boost::asio::const_buffer>::type; #if GENERATING_DOCS /// A bidirectional iterator type that may be used to read elements. @@ -100,7 +97,7 @@ public: const_iterator begin() const; - /// Get a bidirectional iterator for one past the last element. + /// Get a bidirectional iterator to one past the last element. const_iterator end() const; @@ -114,25 +111,6 @@ public: consume(std::size_t n); }; -/** Returns a new, consumed buffer sequence. - - This function returns a new buffer sequence which when iterated, - efficiently represents the portion of the original buffer sequence - with `n` bytes removed from the beginning. - - Copies will be made of the buffer sequence passed, but ownership - of the underlying memory is not transferred. - - @param buffers The buffer sequence to consume. - - @param n The number of bytes to remove from the front. If this is - larger than the size of the buffer sequence, an empty buffer sequence - is returned. -*/ -template -consuming_buffers -consumed_buffers(BufferSequence const& buffers, std::size_t n); - } // beast #include diff --git a/include/beast/core/impl/consuming_buffers.ipp b/include/beast/core/impl/consuming_buffers.ipp index 37c69005..dcfca362 100644 --- a/include/beast/core/impl/consuming_buffers.ipp +++ b/include/beast/core/impl/consuming_buffers.ipp @@ -18,10 +18,10 @@ namespace beast { -template -class consuming_buffers::const_iterator +template +class consuming_buffers::const_iterator { - friend class consuming_buffers; + friend class consuming_buffers; using iter_type = typename BufferSequence::const_iterator; @@ -30,8 +30,12 @@ class consuming_buffers::const_iterator consuming_buffers const* b_ = nullptr; public: - using value_type = - typename std::iterator_traits::value_type; + using value_type = typename std::conditional< + std::is_convertible::value_type, + boost::asio::mutable_buffer>::value, + boost::asio::mutable_buffer, + boost::asio::const_buffer>::type; using pointer = value_type const*; using reference = value_type; using difference_type = std::ptrdiff_t; @@ -59,8 +63,9 @@ public: reference operator*() const { - return it_ == b_->begin_ ? - *it_ + b_->skip_ : *it_; + return it_ == b_->begin_ + ? value_type{*it_} + b_->skip_ + : *it_; } pointer @@ -105,8 +110,8 @@ private: } }; -template -consuming_buffers:: +template +consuming_buffers:: consuming_buffers(consuming_buffers&& other) : consuming_buffers(std::move(other), std::distance( @@ -114,8 +119,8 @@ consuming_buffers(consuming_buffers&& other) { } -template -consuming_buffers:: +template +consuming_buffers:: consuming_buffers(consuming_buffers const& other) : consuming_buffers(other, std::distance( @@ -123,9 +128,9 @@ consuming_buffers(consuming_buffers const& other) { } -template +template auto -consuming_buffers:: +consuming_buffers:: operator=(consuming_buffers&& other) -> consuming_buffers& { @@ -137,9 +142,9 @@ operator=(consuming_buffers&& other) -> return *this; } -template +template auto -consuming_buffers:: +consuming_buffers:: operator=(consuming_buffers const& other) -> consuming_buffers& { @@ -151,35 +156,41 @@ operator=(consuming_buffers const& other) -> return *this; } -template -consuming_buffers:: +template +consuming_buffers:: consuming_buffers(BufferSequence const& bs) : bs_(bs) , begin_(bs_.begin()) { - static_assert(is_BufferSequence::value, - "BufferSequence requirements not met"); + static_assert( + is_BufferSequence::value, + "BufferSequence requirements not met"); } -template +template +inline auto -consuming_buffers::begin() const -> +consuming_buffers:: +begin() const -> const_iterator { return const_iterator{*this, begin_}; } -template +template +inline auto -consuming_buffers::end() const -> +consuming_buffers:: +end() const -> const_iterator { return const_iterator{*this, bs_.end()}; } -template +template void -consuming_buffers::consume(std::size_t n) +consuming_buffers:: +consume(std::size_t n) { using boost::asio::buffer_size; for(;n > 0 && begin_ != bs_.end(); ++begin_) @@ -196,15 +207,6 @@ consuming_buffers::consume(std::size_t n) } } -template -consuming_buffers -consumed_buffers(BufferSequence const& bs, std::size_t n) -{ - consuming_buffers cb(bs); - cb.consume(n); - return cb; -} - } // beast #endif diff --git a/test/core/consuming_buffers.cpp b/test/core/consuming_buffers.cpp index 85700072..71630b0a 100644 --- a/test/core/consuming_buffers.cpp +++ b/test/core/consuming_buffers.cpp @@ -19,6 +19,16 @@ namespace beast { class consuming_buffers_test : public beast::unit_test::suite { public: + template + static + consuming_buffers + consumed_buffers(BufferSequence const& bs, std::size_t n) + { + consuming_buffers cb(bs); + cb.consume(n); + return cb; + } + template static bool diff --git a/test/websocket/utf8_checker.cpp b/test/websocket/utf8_checker.cpp index c52e894f..90d5d697 100644 --- a/test/websocket/utf8_checker.cpp +++ b/test/websocket/utf8_checker.cpp @@ -283,10 +283,10 @@ public: { static std::size_t constexpr size = 3; std::size_t n = s.size(); - auto cb = consumed_buffers( - boost::asio::const_buffers_1( - s.data(), n), 0); - streambuf sb(size); + consuming_buffers< + boost::asio::const_buffers_1> cb{ + boost::asio::const_buffers_1(s.data(), n)}; + streambuf sb{size}; while(n) { auto const amount = (std::min)(n, size);