From b8cf34c691623e4ec329053cbbf68522a855882d Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Thu, 5 Dec 2019 15:12:59 +0900 Subject: Imported Upstream version 1.67.0 --- boost/beast/core/impl/buffered_read_stream.ipp | 23 +- boost/beast/core/impl/buffers_cat.ipp | 327 ++++++++----------------- boost/beast/core/impl/buffers_prefix.ipp | 2 +- boost/beast/core/impl/buffers_suffix.ipp | 3 +- boost/beast/core/impl/file_posix.ipp | 10 +- boost/beast/core/impl/file_stdio.ipp | 10 +- boost/beast/core/impl/file_win32.ipp | 18 +- boost/beast/core/impl/handler_ptr.ipp | 149 +++++------ boost/beast/core/impl/multi_buffer.ipp | 2 +- boost/beast/core/impl/static_buffer.ipp | 23 +- 10 files changed, 226 insertions(+), 341 deletions(-) (limited to 'boost/beast/core/impl') diff --git a/boost/beast/core/impl/buffered_read_stream.ipp b/boost/beast/core/impl/buffered_read_stream.ipp index 9e9fa53065..1ae76b4d34 100644 --- a/boost/beast/core/impl/buffered_read_stream.ipp +++ b/boost/beast/core/impl/buffered_read_stream.ipp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,7 @@ class buffered_read_stream< public: read_some_op(read_some_op&&) = default; - read_some_op(read_some_op const&) = default; + read_some_op(read_some_op const&) = delete; template read_some_op(DeducedHandler&& h, @@ -55,7 +56,7 @@ public: allocator_type get_allocator() const noexcept { - return boost::asio::get_associated_allocator(h_); + return (boost::asio::get_associated_allocator)(h_); } using executor_type = @@ -65,7 +66,7 @@ public: executor_type get_executor() const noexcept { - return boost::asio::get_associated_executor( + return (boost::asio::get_associated_executor)( h_, s_.get_executor()); } @@ -80,6 +81,14 @@ public: return asio_handler_is_continuation( std::addressof(op->h_)); } + + template + friend + void asio_handler_invoke(Function&& f, read_some_op* op) + { + using boost::asio::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } }; template @@ -121,7 +130,7 @@ read_some_op::operator()( case 2: s_.buffer_.commit(bytes_transferred); - BOOST_BEAST_FALLTHROUGH; + BOOST_FALLTHROUGH; case 3: bytes_transferred = @@ -233,11 +242,11 @@ async_read_some( if(buffer_.size() == 0 && capacity_ == 0) return next_layer_.async_read_some(buffers, std::forward(handler)); - boost::asio::async_completion init{handler}; + BOOST_BEAST_HANDLER_INIT( + ReadHandler, void(error_code, std::size_t)); read_some_op{ - init.completion_handler, *this, buffers}( + std::move(init.completion_handler), *this, buffers}( error_code{}, 0); return init.result.get(); } diff --git a/boost/beast/core/impl/buffers_cat.ipp b/boost/beast/core/impl/buffers_cat.ipp index d92d55233a..2e82e887fc 100644 --- a/boost/beast/core/impl/buffers_cat.ipp +++ b/boost/beast/core/impl/buffers_cat.ipp @@ -11,9 +11,9 @@ #define BOOST_BEAST_IMPL_BUFFERS_CAT_IPP #include +#include #include #include -#include #include #include #include @@ -27,38 +27,28 @@ namespace beast { template class buffers_cat_view::const_iterator { - std::size_t n_; - std::tuple const* bn_; - std::array::type...>()> buf_; + // VFALCO The logic to skip empty sequences fails + // if there is just one buffer in the list. + static_assert(sizeof...(Bn) >= 2, + "A minimum of two sequences are required"); - friend class buffers_cat_view; - - template - using C = std::integral_constant; + struct past_end + { + operator bool() const noexcept + { + return true; + } + }; - template - using iter_t = typename detail::buffer_sequence_iterator< - typename std::tuple_element>::type>::type; + std::tuple const* bn_ = nullptr; + detail::variant::type..., + past_end> it_; - template - iter_t& - iter() - { - // type-pun - return *reinterpret_cast< - iter_t*>(static_cast(buf_.data())); - } + friend class buffers_cat_view; template - iter_t const& - iter() const - { - // type-pun - return *reinterpret_cast< - iter_t const*>(static_cast< - void const*>(buf_.data())); - } + using C = std::integral_constant; public: using value_type = typename @@ -69,12 +59,11 @@ public: using iterator_category = std::bidirectional_iterator_tag; - ~const_iterator(); - const_iterator(); - const_iterator(const_iterator&& other); - const_iterator(const_iterator const& other); - const_iterator& operator=(const_iterator&& other); - const_iterator& operator=(const_iterator const& other); + const_iterator() = default; + const_iterator(const_iterator&& other) = default; + const_iterator(const_iterator const& other) = default; + const_iterator& operator=(const_iterator&& other) = default; + const_iterator& operator=(const_iterator const& other) = default; bool operator==(const_iterator const& other) const; @@ -97,9 +86,11 @@ public: const_iterator operator++(int); + // deprecated const_iterator& operator--(); + // deprecated const_iterator operator--(int); @@ -107,13 +98,6 @@ private: const_iterator( std::tuple const& bn, bool at_end); - void - construct(C const&) - { - auto constexpr I = sizeof...(Bn); - n_ = I; - } - template void construct(C const&) @@ -121,144 +105,90 @@ private: if(boost::asio::buffer_size( std::get(*bn_)) != 0) { - n_ = I; - new(&buf_[0]) iter_t{ + it_.template emplace( boost::asio::buffer_sequence_begin( - std::get(*bn_))}; + std::get(*bn_))); return; } construct(C{}); } void - rconstruct(C<0> const&) - { - auto constexpr I = 0; - if(boost::asio::buffer_size( - std::get(*bn_)) != 0) - { - n_ = I; - new(&buf_[0]) iter_t{ - boost::asio::buffer_sequence_end( - std::get(*bn_))}; - return; - } - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); - } - - template - void - rconstruct(C const&) + construct(C const&) { - if(boost::asio::buffer_size( - std::get(*bn_)) != 0) - { - n_ = I; - new(&buf_[0]) iter_t{ - boost::asio::buffer_sequence_end( - std::get(*bn_))}; - return; - } - rconstruct(C{}); + auto constexpr I = sizeof...(Bn)-1; + it_.template emplace( + boost::asio::buffer_sequence_begin( + std::get(*bn_))); } void - destroy(C const&) + construct(C const&) { - return; + // end + auto constexpr I = sizeof...(Bn); + it_.template emplace(); } template void - destroy(C const&) + next(C const&) { - if(n_ == I) + if(boost::asio::buffer_size( + std::get(*bn_)) != 0) { - using Iter = iter_t; - iter().~Iter(); + it_.template emplace( + boost::asio::buffer_sequence_begin( + std::get(*bn_))); return; } - destroy(C{}); + next(C{}); } void - move(const_iterator&&, - C const&) + next(C const&) { + // end + auto constexpr I = sizeof...(Bn); + it_.template emplace(); } template void - move(const_iterator&& other, - C const&) + prev(C const&) { - if(n_ == I) + if(boost::asio::buffer_size( + std::get(*bn_)) != 0) { - new(&buf_[0]) iter_t{ - std::move(other.iter())}; + it_.template emplace( + boost::asio::buffer_sequence_end( + std::get(*bn_))); return; } - move(std::move(other), C{}); - } - - void - copy(const_iterator const&, - C const&) - { + prev(C{}); } - template void - copy(const_iterator const& other, - C const&) + prev(C<0> const&) { - if(n_ == I) - { - new(&buf_[0]) iter_t{ - other.iter()}; - return; - } - copy(other, C{}); - } - - bool - equal(const_iterator const&, - C const&) const - { - return true; - } - - template - bool - equal(const_iterator const& other, - C const&) const - { - if(n_ == I) - return iter() == other.iter(); - return equal(other, C{}); - } - - [[noreturn]] - reference - dereference(C const&) const - { - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); + auto constexpr I = 0; + it_.template emplace( + boost::asio::buffer_sequence_end( + std::get(*bn_))); } template reference dereference(C const&) const { - if(n_ == I) - return *iter(); + if(it_.index() == I+1) + return *it_.template get(); return dereference(C{}); } [[noreturn]] - void - increment(C const&) + reference + dereference(C const&) const { BOOST_THROW_EXCEPTION(std::logic_error{ "invalid iterator"}); @@ -268,25 +198,31 @@ private: void increment(C const&) { - if(n_ == I) + if(it_.index() == I+1) { - if(++iter() != + if(++it_.template get() != boost::asio::buffer_sequence_end( std::get(*bn_))) return; - using Iter = iter_t; - iter().~Iter(); - return construct(C{}); + return next(C{}); } increment(C{}); } + [[noreturn]] + void + increment(C const&) + { + BOOST_THROW_EXCEPTION(std::logic_error{ + "invalid iterator"}); + } + void decrement(C const&) { auto constexpr I = sizeof...(Bn); - if(n_ == I) - rconstruct(C{}); + if(it_.index() == I+1) + prev(C{}); decrement(C{}); } @@ -294,19 +230,16 @@ private: void decrement(C const&) { - if(n_ == I) + if(it_.index() == I+1) { - if(iter() != + if(it_.template get() != boost::asio::buffer_sequence_begin( std::get(*bn_))) { - --iter(); + --it_.template get(); return; } - --n_; - using Iter = iter_t; - iter().~Iter(); - rconstruct(C{}); + prev(C{}); } decrement(C{}); } @@ -315,11 +248,11 @@ private: decrement(C<0> const&) { auto constexpr I = 0; - if(iter() != + if(it_.template get() != boost::asio::buffer_sequence_begin( std::get(*bn_))) { - --iter(); + --it_.template get(); return; } BOOST_THROW_EXCEPTION(std::logic_error{ @@ -331,97 +264,33 @@ private: template buffers_cat_view:: -const_iterator::~const_iterator() -{ - destroy(C<0>{}); -} - -template -buffers_cat_view:: -const_iterator::const_iterator() - : n_(sizeof...(Bn)) - , bn_(nullptr) -{ -} - -template -buffers_cat_view:: -const_iterator::const_iterator( +const_iterator:: +const_iterator( std::tuple const& bn, bool at_end) : bn_(&bn) { - if(at_end) - n_ = sizeof...(Bn); - else + if(! at_end) construct(C<0>{}); -} - -template -buffers_cat_view:: -const_iterator::const_iterator(const_iterator&& other) - : n_(other.n_) - , bn_(other.bn_) -{ - move(std::move(other), C<0>{}); -} - -template -buffers_cat_view:: -const_iterator::const_iterator(const_iterator const& other) - : n_(other.n_) - , bn_(other.bn_) -{ - copy(other, C<0>{}); -} - -template -auto -buffers_cat_view:: -const_iterator::operator=(const_iterator&& other) -> - const_iterator& -{ - if(&other == this) - return *this; - destroy(C<0>{}); - n_ = other.n_; - bn_ = other.bn_; - // VFALCO What about exceptions? - move(std::move(other), C<0>{}); - return *this; -} - -template -auto -buffers_cat_view:: -const_iterator::operator=(const_iterator const& other) -> -const_iterator& -{ - if(&other == this) - return *this; - destroy(C<0>{}); - n_ = other.n_; - bn_ = other.bn_; - // VFALCO What about exceptions? - copy(other, C<0>{}); - return *this; + else + construct(C{}); } template bool buffers_cat_view:: -const_iterator::operator==(const_iterator const& other) const +const_iterator:: +operator==(const_iterator const& other) const { if(bn_ != other.bn_) return false; - if(n_ != other.n_) - return false; - return equal(other, C<0>{}); + return it_ == other.it_; } template auto buffers_cat_view:: -const_iterator::operator*() const -> +const_iterator:: +operator*() const -> reference { return dereference(C<0>{}); @@ -430,7 +299,8 @@ const_iterator::operator*() const -> template auto buffers_cat_view:: -const_iterator::operator++() -> +const_iterator:: +operator++() -> const_iterator& { increment(C<0>{}); @@ -440,7 +310,8 @@ const_iterator::operator++() -> template auto buffers_cat_view:: -const_iterator::operator++(int) -> +const_iterator:: +operator++(int) -> const_iterator { auto temp = *this; @@ -451,7 +322,8 @@ const_iterator::operator++(int) -> template auto buffers_cat_view:: -const_iterator::operator--() -> +const_iterator:: +operator--() -> const_iterator& { decrement(C{}); @@ -461,7 +333,8 @@ const_iterator::operator--() -> template auto buffers_cat_view:: -const_iterator::operator--(int) -> +const_iterator:: +operator--(int) -> const_iterator { auto temp = *this; diff --git a/boost/beast/core/impl/buffers_prefix.ipp b/boost/beast/core/impl/buffers_prefix.ipp index 0bb92cc3ae..a45483854f 100644 --- a/boost/beast/core/impl/buffers_prefix.ipp +++ b/boost/beast/core/impl/buffers_prefix.ipp @@ -53,7 +53,7 @@ class buffers_prefix_view::const_iterator public: using value_type = typename std::conditional< - std::is_convertible::value_type, boost::asio::mutable_buffer>::value, boost::asio::mutable_buffer, diff --git a/boost/beast/core/impl/buffers_suffix.ipp b/boost/beast/core/impl/buffers_suffix.ipp index 6356d63e0c..4385fe500d 100644 --- a/boost/beast/core/impl/buffers_suffix.ipp +++ b/boost/beast/core/impl/buffers_suffix.ipp @@ -11,6 +11,7 @@ #define BOOST_BEAST_IMPL_BUFFERS_SUFFIX_IPP #include +#include #include #include #include @@ -33,7 +34,7 @@ class buffers_suffix::const_iterator public: using value_type = typename std::conditional< - std::is_convertible::value_type, boost::asio::mutable_buffer>::value, boost::asio::mutable_buffer, diff --git a/boost/beast/core/impl/file_posix.ipp b/boost/beast/core/impl/file_posix.ipp index 96ccdc3bbe..c30a7d020f 100644 --- a/boost/beast/core/impl/file_posix.ipp +++ b/boost/beast/core/impl/file_posix.ipp @@ -224,7 +224,7 @@ size(error_code& ec) const { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } struct stat st; @@ -244,7 +244,7 @@ pos(error_code& ec) const { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } auto const result = ::lseek(fd_, 0, SEEK_CUR); @@ -264,7 +264,7 @@ seek(std::uint64_t offset, error_code& ec) { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return; } auto const result = ::lseek(fd_, offset, SEEK_SET); @@ -283,7 +283,7 @@ read(void* buffer, std::size_t n, error_code& ec) const { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nread = 0; @@ -319,7 +319,7 @@ write(void const* buffer, std::size_t n, error_code& ec) { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nwritten = 0; diff --git a/boost/beast/core/impl/file_stdio.ipp b/boost/beast/core/impl/file_stdio.ipp index ca5cb0cbde..60a0f3fc0e 100644 --- a/boost/beast/core/impl/file_stdio.ipp +++ b/boost/beast/core/impl/file_stdio.ipp @@ -122,7 +122,7 @@ size(error_code& ec) const { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } long pos = std::ftell(f_); @@ -159,7 +159,7 @@ pos(error_code& ec) const { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } long pos = std::ftell(f_); @@ -179,7 +179,7 @@ seek(std::uint64_t offset, error_code& ec) { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return; } if(offset > (std::numeric_limits::max)()) @@ -202,7 +202,7 @@ read(void* buffer, std::size_t n, error_code& ec) const { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } auto nread = std::fread(buffer, 1, n, f_); @@ -221,7 +221,7 @@ write(void const* buffer, std::size_t n, error_code& ec) { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } auto nwritten = std::fwrite(buffer, 1, n, f_); diff --git a/boost/beast/core/impl/file_win32.ipp b/boost/beast/core/impl/file_win32.ipp index de4abae41f..c1b4cc6c7d 100644 --- a/boost/beast/core/impl/file_win32.ipp +++ b/boost/beast/core/impl/file_win32.ipp @@ -216,7 +216,7 @@ size(error_code& ec) const { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } boost::winapi::LARGE_INTEGER_ fileSize; @@ -237,7 +237,7 @@ pos(error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } boost::winapi::LARGE_INTEGER_ in; @@ -261,7 +261,7 @@ seek(std::uint64_t offset, error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return; } boost::winapi::LARGE_INTEGER_ in; @@ -283,7 +283,7 @@ read(void* buffer, std::size_t n, error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nread = 0; @@ -300,9 +300,9 @@ read(void* buffer, std::size_t n, error_code& ec) boost::winapi::DWORD_ bytesRead; if(! ::ReadFile(h_, buffer, amount, &bytesRead, 0)) { - auto const dwError = ::GetLastError(); + auto const dwError = boost::winapi::GetLastError(); if(dwError != boost::winapi::ERROR_HANDLE_EOF_) - ec.assign(::GetLastError(), system_category()); + ec.assign(dwError, system_category()); else ec.assign(0, ec.category()); return nread; @@ -324,7 +324,7 @@ write(void const* buffer, std::size_t n, error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nwritten = 0; @@ -341,9 +341,9 @@ write(void const* buffer, std::size_t n, error_code& ec) boost::winapi::DWORD_ bytesWritten; if(! ::WriteFile(h_, buffer, amount, &bytesWritten, 0)) { - auto const dwError = ::GetLastError(); + auto const dwError = boost::winapi::GetLastError(); if(dwError != boost::winapi::ERROR_HANDLE_EOF_) - ec.assign(::GetLastError(), system_category()); + ec.assign(dwError, system_category()); else ec.assign(0, ec.category()); return nwritten; diff --git a/boost/beast/core/impl/handler_ptr.ipp b/boost/beast/core/impl/handler_ptr.ipp index 15a159a8fd..99d1a894d5 100644 --- a/boost/beast/core/impl/handler_ptr.ipp +++ b/boost/beast/core/impl/handler_ptr.ipp @@ -18,87 +18,72 @@ namespace boost { namespace beast { template -template -inline -handler_ptr::P:: -P(DeducedHandler&& h, Args&&... args) - : n(1) - , handler(std::forward(h)) +void +handler_ptr:: +clear() { - typename std::allocator_traits< - boost::asio::associated_allocator_t>:: - template rebind_alloc alloc{ - boost::asio::get_associated_allocator(handler)}; - t = std::allocator_traits::allocate(alloc, 1); - try - { - t = new(t) T{handler, - std::forward(args)...}; - } - catch(...) - { - std::allocator_traits< - decltype(alloc)>::deallocate(alloc, t, 1); - throw; - } + typename beast::detail::allocator_traits< + boost::asio::associated_allocator_t< + Handler>>::template rebind_alloc alloc( + boost::asio::get_associated_allocator( + handler())); + beast::detail::allocator_traits< + decltype(alloc)>::destroy(alloc, t_); + beast::detail::allocator_traits< + decltype(alloc)>::deallocate(alloc, t_, 1); + t_ = nullptr; } template handler_ptr:: ~handler_ptr() { - if(! p_) - return; - if(--p_->n) - return; - if(p_->t) + if(t_) { - p_->t->~T(); - typename std::allocator_traits< - boost::asio::associated_allocator_t>:: - template rebind_alloc alloc{ - boost::asio::get_associated_allocator( - p_->handler)}; - std::allocator_traits< - decltype(alloc)>::deallocate(alloc, p_->t, 1); + clear(); + handler().~Handler(); } - delete p_; } template handler_ptr:: handler_ptr(handler_ptr&& other) - : p_(other.p_) + : t_(other.t_) { - other.p_ = nullptr; -} - -template -handler_ptr:: -handler_ptr(handler_ptr const& other) - : p_(other.p_) -{ - if(p_) - ++p_->n; -} - -template -template -handler_ptr:: -handler_ptr(Handler&& handler, Args&&... args) - : p_(new P{std::move(handler), - std::forward(args)...}) -{ - BOOST_STATIC_ASSERT(! std::is_array::value); + if(other.t_) + { + new(&h_) Handler(std::move(other.handler())); + other.handler().~Handler(); + other.t_ = nullptr; + } } template -template +template handler_ptr:: -handler_ptr(Handler const& handler, Args&&... args) - : p_(new P{handler, std::forward(args)...}) +handler_ptr(DeducedHandler&& h, Args&&... args) { BOOST_STATIC_ASSERT(! std::is_array::value); + typename beast::detail::allocator_traits< + boost::asio::associated_allocator_t< + Handler>>::template rebind_alloc alloc{ + boost::asio::get_associated_allocator(h)}; + using A = decltype(alloc); + bool destroy = false; + auto deleter = [&alloc, &destroy](T* p) + { + if(destroy) + beast::detail::allocator_traits::destroy(alloc, p); + beast::detail::allocator_traits::deallocate(alloc, p, 1); + }; + std::unique_ptr t{ + beast::detail::allocator_traits::allocate(alloc, 1), deleter}; + beast::detail::allocator_traits::construct(alloc, t.get(), + static_cast(h), + std::forward(args)...); + destroy = true; + new(&h_) Handler(std::forward(h)); + t_ = t.release(); } template @@ -107,18 +92,16 @@ handler_ptr:: release_handler() -> handler_type { - BOOST_ASSERT(p_); - BOOST_ASSERT(p_->t); - p_->t->~T(); - typename std::allocator_traits< - boost::asio::associated_allocator_t>:: - template rebind_alloc alloc{ - boost::asio::get_associated_allocator( - p_->handler)}; - std::allocator_traits< - decltype(alloc)>::deallocate(alloc, p_->t, 1); - p_->t = nullptr; - return std::move(p_->handler); + BOOST_ASSERT(t_); + clear(); + auto deleter = [](Handler* h) + { + h->~Handler(); + }; + std::unique_ptr< + Handler, decltype(deleter)> destroyer{ + &handler(), deleter}; + return std::move(handler()); } template @@ -127,18 +110,16 @@ void handler_ptr:: invoke(Args&&... args) { - BOOST_ASSERT(p_); - BOOST_ASSERT(p_->t); - p_->t->~T(); - typename std::allocator_traits< - boost::asio::associated_allocator_t>:: - template rebind_alloc alloc{ - boost::asio::get_associated_allocator( - p_->handler)}; - std::allocator_traits< - decltype(alloc)>::deallocate(alloc, p_->t, 1); - p_->t = nullptr; - p_->handler(std::forward(args)...); + BOOST_ASSERT(t_); + clear(); + auto deleter = [](Handler* h) + { + h->~Handler(); + }; + std::unique_ptr< + Handler, decltype(deleter)> destroyer{ + &handler(), deleter}; + handler()(std::forward(args)...); } } // beast diff --git a/boost/beast/core/impl/multi_buffer.ipp b/boost/beast/core/impl/multi_buffer.ipp index 7b66694cb3..e7ae541f9c 100644 --- a/boost/beast/core/impl/multi_buffer.ipp +++ b/boost/beast/core/impl/multi_buffer.ipp @@ -132,7 +132,7 @@ class basic_multi_buffer::const_buffers_type const_buffers_type(basic_multi_buffer const& b); public: - using value_type = boost::asio::mutable_buffer; + using value_type = boost::asio::const_buffer; class const_iterator; diff --git a/boost/beast/core/impl/static_buffer.ipp b/boost/beast/core/impl/static_buffer.ipp index d93a1e6911..2fdb2d9a8a 100644 --- a/boost/beast/core/impl/static_buffer.ipp +++ b/boost/beast/core/impl/static_buffer.ipp @@ -35,9 +35,30 @@ static_buffer_base:: data() const -> const_buffers_type { - using boost::asio::mutable_buffer; + using boost::asio::const_buffer; const_buffers_type result; if(in_off_ + in_size_ <= capacity_) + { + result[0] = const_buffer{begin_ + in_off_, in_size_}; + result[1] = const_buffer{begin_, 0}; + } + else + { + result[0] = const_buffer{begin_ + in_off_, capacity_ - in_off_}; + result[1] = const_buffer{begin_, in_size_ - (capacity_ - in_off_)}; + } + return result; +} + +inline +auto +static_buffer_base:: +mutable_data() -> + mutable_buffers_type +{ + using boost::asio::mutable_buffer; + mutable_buffers_type result; + if(in_off_ + in_size_ <= capacity_) { result[0] = mutable_buffer{begin_ + in_off_, in_size_}; result[1] = mutable_buffer{begin_, 0}; -- cgit v1.2.3