diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
commit | b8cf34c691623e4ec329053cbbf68522a855882d (patch) | |
tree | 34da08632a99677f6b79ecb65e5b655a5b69a67f /boost/beast/core/impl | |
parent | 3fdc3e5ee96dca5b11d1694975a65200787eab86 (diff) | |
download | boost-upstream/1.67.0.tar.gz boost-upstream/1.67.0.tar.bz2 boost-upstream/1.67.0.zip |
Imported Upstream version 1.67.0upstream/1.67.0
Diffstat (limited to 'boost/beast/core/impl')
-rw-r--r-- | boost/beast/core/impl/buffered_read_stream.ipp | 23 | ||||
-rw-r--r-- | boost/beast/core/impl/buffers_cat.ipp | 327 | ||||
-rw-r--r-- | boost/beast/core/impl/buffers_prefix.ipp | 2 | ||||
-rw-r--r-- | boost/beast/core/impl/buffers_suffix.ipp | 3 | ||||
-rw-r--r-- | boost/beast/core/impl/file_posix.ipp | 10 | ||||
-rw-r--r-- | boost/beast/core/impl/file_stdio.ipp | 10 | ||||
-rw-r--r-- | boost/beast/core/impl/file_win32.ipp | 18 | ||||
-rw-r--r-- | boost/beast/core/impl/handler_ptr.ipp | 149 | ||||
-rw-r--r-- | boost/beast/core/impl/multi_buffer.ipp | 2 | ||||
-rw-r--r-- | boost/beast/core/impl/static_buffer.ipp | 23 |
10 files changed, 226 insertions, 341 deletions
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 <boost/asio/associated_allocator.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/handler_continuation_hook.hpp> +#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/post.hpp> #include <boost/throw_exception.hpp> @@ -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<class DeducedHandler, class... Args> 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<class Function> + 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<class Stream, class DynamicBuffer> @@ -121,7 +130,7 @@ read_some_op<MutableBufferSequence, Handler>::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<ReadHandler>(handler)); - boost::asio::async_completion<ReadHandler, - void(error_code, std::size_t)> init{handler}; + BOOST_BEAST_HANDLER_INIT( + ReadHandler, void(error_code, std::size_t)); read_some_op<MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE( ReadHandler, void(error_code, std::size_t))>{ - 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 <boost/beast/core/detail/type_traits.hpp> +#include <boost/beast/core/detail/variant.hpp> #include <boost/asio/buffer.hpp> #include <boost/throw_exception.hpp> -#include <array> #include <cstdint> #include <iterator> #include <new> @@ -27,38 +27,28 @@ namespace beast { template<class... Bn> class buffers_cat_view<Bn...>::const_iterator { - std::size_t n_; - std::tuple<Bn...> const* bn_; - std::array<char, detail::max_sizeof< - typename detail::buffer_sequence_iterator<Bn>::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<Bn...>; - - template<std::size_t I> - using C = std::integral_constant<std::size_t, I>; + struct past_end + { + operator bool() const noexcept + { + return true; + } + }; - template<std::size_t I> - using iter_t = typename detail::buffer_sequence_iterator< - typename std::tuple_element<I, std::tuple<Bn...>>::type>::type; + std::tuple<Bn...> const* bn_ = nullptr; + detail::variant<typename + detail::buffer_sequence_iterator<Bn>::type..., + past_end> it_; - template<std::size_t I> - iter_t<I>& - iter() - { - // type-pun - return *reinterpret_cast< - iter_t<I>*>(static_cast<void*>(buf_.data())); - } + friend class buffers_cat_view<Bn...>; template<std::size_t I> - iter_t<I> const& - iter() const - { - // type-pun - return *reinterpret_cast< - iter_t<I> const*>(static_cast< - void const*>(buf_.data())); - } + using C = std::integral_constant<std::size_t, I>; 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<Bn...> const& bn, bool at_end); - void - construct(C<sizeof...(Bn)> const&) - { - auto constexpr I = sizeof...(Bn); - n_ = I; - } - template<std::size_t I> void construct(C<I> const&) @@ -121,144 +105,90 @@ private: if(boost::asio::buffer_size( std::get<I>(*bn_)) != 0) { - n_ = I; - new(&buf_[0]) iter_t<I>{ + it_.template emplace<I+1>( boost::asio::buffer_sequence_begin( - std::get<I>(*bn_))}; + std::get<I>(*bn_))); return; } construct(C<I+1>{}); } void - rconstruct(C<0> const&) - { - auto constexpr I = 0; - if(boost::asio::buffer_size( - std::get<I>(*bn_)) != 0) - { - n_ = I; - new(&buf_[0]) iter_t<I>{ - boost::asio::buffer_sequence_end( - std::get<I>(*bn_))}; - return; - } - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); - } - - template<std::size_t I> - void - rconstruct(C<I> const&) + construct(C<sizeof...(Bn)-1> const&) { - if(boost::asio::buffer_size( - std::get<I>(*bn_)) != 0) - { - n_ = I; - new(&buf_[0]) iter_t<I>{ - boost::asio::buffer_sequence_end( - std::get<I>(*bn_))}; - return; - } - rconstruct(C<I-1>{}); + auto constexpr I = sizeof...(Bn)-1; + it_.template emplace<I+1>( + boost::asio::buffer_sequence_begin( + std::get<I>(*bn_))); } void - destroy(C<sizeof...(Bn)> const&) + construct(C<sizeof...(Bn)> const&) { - return; + // end + auto constexpr I = sizeof...(Bn); + it_.template emplace<I+1>(); } template<std::size_t I> void - destroy(C<I> const&) + next(C<I> const&) { - if(n_ == I) + if(boost::asio::buffer_size( + std::get<I>(*bn_)) != 0) { - using Iter = iter_t<I>; - iter<I>().~Iter(); + it_.template emplace<I+1>( + boost::asio::buffer_sequence_begin( + std::get<I>(*bn_))); return; } - destroy(C<I+1>{}); + next(C<I+1>{}); } void - move(const_iterator&&, - C<sizeof...(Bn)> const&) + next(C<sizeof...(Bn)> const&) { + // end + auto constexpr I = sizeof...(Bn); + it_.template emplace<I+1>(); } template<std::size_t I> void - move(const_iterator&& other, - C<I> const&) + prev(C<I> const&) { - if(n_ == I) + if(boost::asio::buffer_size( + std::get<I>(*bn_)) != 0) { - new(&buf_[0]) iter_t<I>{ - std::move(other.iter<I>())}; + it_.template emplace<I+1>( + boost::asio::buffer_sequence_end( + std::get<I>(*bn_))); return; } - move(std::move(other), C<I+1>{}); - } - - void - copy(const_iterator const&, - C<sizeof...(Bn)> const&) - { + prev(C<I-1>{}); } - template<std::size_t I> void - copy(const_iterator const& other, - C<I> const&) + prev(C<0> const&) { - if(n_ == I) - { - new(&buf_[0]) iter_t<I>{ - other.iter<I>()}; - return; - } - copy(other, C<I+1>{}); - } - - bool - equal(const_iterator const&, - C<sizeof...(Bn)> const&) const - { - return true; - } - - template<std::size_t I> - bool - equal(const_iterator const& other, - C<I> const&) const - { - if(n_ == I) - return iter<I>() == other.iter<I>(); - return equal(other, C<I+1>{}); - } - - [[noreturn]] - reference - dereference(C<sizeof...(Bn)> const&) const - { - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); + auto constexpr I = 0; + it_.template emplace<I+1>( + boost::asio::buffer_sequence_end( + std::get<I>(*bn_))); } template<std::size_t I> reference dereference(C<I> const&) const { - if(n_ == I) - return *iter<I>(); + if(it_.index() == I+1) + return *it_.template get<I+1>(); return dereference(C<I+1>{}); } [[noreturn]] - void - increment(C<sizeof...(Bn)> const&) + reference + dereference(C<sizeof...(Bn)> const&) const { BOOST_THROW_EXCEPTION(std::logic_error{ "invalid iterator"}); @@ -268,25 +198,31 @@ private: void increment(C<I> const&) { - if(n_ == I) + if(it_.index() == I+1) { - if(++iter<I>() != + if(++it_.template get<I+1>() != boost::asio::buffer_sequence_end( std::get<I>(*bn_))) return; - using Iter = iter_t<I>; - iter<I>().~Iter(); - return construct(C<I+1>{}); + return next(C<I+1>{}); } increment(C<I+1>{}); } + [[noreturn]] + void + increment(C<sizeof...(Bn)> const&) + { + BOOST_THROW_EXCEPTION(std::logic_error{ + "invalid iterator"}); + } + void decrement(C<sizeof...(Bn)> const&) { auto constexpr I = sizeof...(Bn); - if(n_ == I) - rconstruct(C<I-1>{}); + if(it_.index() == I+1) + prev(C<I-1>{}); decrement(C<I-1>{}); } @@ -294,19 +230,16 @@ private: void decrement(C<I> const&) { - if(n_ == I) + if(it_.index() == I+1) { - if(iter<I>() != + if(it_.template get<I+1>() != boost::asio::buffer_sequence_begin( std::get<I>(*bn_))) { - --iter<I>(); + --it_.template get<I+1>(); return; } - --n_; - using Iter = iter_t<I>; - iter<I>().~Iter(); - rconstruct(C<I-1>{}); + prev(C<I-1>{}); } decrement(C<I-1>{}); } @@ -315,11 +248,11 @@ private: decrement(C<0> const&) { auto constexpr I = 0; - if(iter<I>() != + if(it_.template get<I+1>() != boost::asio::buffer_sequence_begin( std::get<I>(*bn_))) { - --iter<I>(); + --it_.template get<I+1>(); return; } BOOST_THROW_EXCEPTION(std::logic_error{ @@ -331,97 +264,33 @@ private: template<class... Bn> buffers_cat_view<Bn...>:: -const_iterator::~const_iterator() -{ - destroy(C<0>{}); -} - -template<class... Bn> -buffers_cat_view<Bn...>:: -const_iterator::const_iterator() - : n_(sizeof...(Bn)) - , bn_(nullptr) -{ -} - -template<class... Bn> -buffers_cat_view<Bn...>:: -const_iterator::const_iterator( +const_iterator:: +const_iterator( std::tuple<Bn...> const& bn, bool at_end) : bn_(&bn) { - if(at_end) - n_ = sizeof...(Bn); - else + if(! at_end) construct(C<0>{}); -} - -template<class... Bn> -buffers_cat_view<Bn...>:: -const_iterator::const_iterator(const_iterator&& other) - : n_(other.n_) - , bn_(other.bn_) -{ - move(std::move(other), C<0>{}); -} - -template<class... Bn> -buffers_cat_view<Bn...>:: -const_iterator::const_iterator(const_iterator const& other) - : n_(other.n_) - , bn_(other.bn_) -{ - copy(other, C<0>{}); -} - -template<class... Bn> -auto -buffers_cat_view<Bn...>:: -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<class... Bn> -auto -buffers_cat_view<Bn...>:: -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<sizeof...(Bn)>{}); } template<class... Bn> bool buffers_cat_view<Bn...>:: -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<class... Bn> auto buffers_cat_view<Bn...>:: -const_iterator::operator*() const -> +const_iterator:: +operator*() const -> reference { return dereference(C<0>{}); @@ -430,7 +299,8 @@ const_iterator::operator*() const -> template<class... Bn> auto buffers_cat_view<Bn...>:: -const_iterator::operator++() -> +const_iterator:: +operator++() -> const_iterator& { increment(C<0>{}); @@ -440,7 +310,8 @@ const_iterator::operator++() -> template<class... Bn> auto buffers_cat_view<Bn...>:: -const_iterator::operator++(int) -> +const_iterator:: +operator++(int) -> const_iterator { auto temp = *this; @@ -451,7 +322,8 @@ const_iterator::operator++(int) -> template<class... Bn> auto buffers_cat_view<Bn...>:: -const_iterator::operator--() -> +const_iterator:: +operator--() -> const_iterator& { decrement(C<sizeof...(Bn)>{}); @@ -461,7 +333,8 @@ const_iterator::operator--() -> template<class... Bn> auto buffers_cat_view<Bn...>:: -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<BufferSequence>::const_iterator public: using value_type = typename std::conditional< - std::is_convertible<typename + boost::is_convertible<typename std::iterator_traits<iter_type>::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 <boost/beast/core/type_traits.hpp> +#include <boost/type_traits.hpp> #include <algorithm> #include <cstdint> #include <iterator> @@ -33,7 +34,7 @@ class buffers_suffix<Buffers>::const_iterator public: using value_type = typename std::conditional< - std::is_convertible<typename + boost::is_convertible<typename std::iterator_traits<iter_type>::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<long>::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<class T, class Handler> -template<class DeducedHandler, class... Args> -inline -handler_ptr<T, Handler>::P:: -P(DeducedHandler&& h, Args&&... args) - : n(1) - , handler(std::forward<DeducedHandler>(h)) +void +handler_ptr<T, Handler>:: +clear() { - typename std::allocator_traits< - boost::asio::associated_allocator_t<Handler>>:: - template rebind_alloc<T> alloc{ - boost::asio::get_associated_allocator(handler)}; - t = std::allocator_traits<decltype(alloc)>::allocate(alloc, 1); - try - { - t = new(t) T{handler, - std::forward<Args>(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<T> 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<class T, class Handler> handler_ptr<T, Handler>:: ~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<Handler>>:: - template rebind_alloc<T> alloc{ - boost::asio::get_associated_allocator( - p_->handler)}; - std::allocator_traits< - decltype(alloc)>::deallocate(alloc, p_->t, 1); + clear(); + handler().~Handler(); } - delete p_; } template<class T, class Handler> handler_ptr<T, Handler>:: handler_ptr(handler_ptr&& other) - : p_(other.p_) + : t_(other.t_) { - other.p_ = nullptr; -} - -template<class T, class Handler> -handler_ptr<T, Handler>:: -handler_ptr(handler_ptr const& other) - : p_(other.p_) -{ - if(p_) - ++p_->n; -} - -template<class T, class Handler> -template<class... Args> -handler_ptr<T, Handler>:: -handler_ptr(Handler&& handler, Args&&... args) - : p_(new P{std::move(handler), - std::forward<Args>(args)...}) -{ - BOOST_STATIC_ASSERT(! std::is_array<T>::value); + if(other.t_) + { + new(&h_) Handler(std::move(other.handler())); + other.handler().~Handler(); + other.t_ = nullptr; + } } template<class T, class Handler> -template<class... Args> +template<class DeducedHandler, class... Args> handler_ptr<T, Handler>:: -handler_ptr(Handler const& handler, Args&&... args) - : p_(new P{handler, std::forward<Args>(args)...}) +handler_ptr(DeducedHandler&& h, Args&&... args) { BOOST_STATIC_ASSERT(! std::is_array<T>::value); + typename beast::detail::allocator_traits< + boost::asio::associated_allocator_t< + Handler>>::template rebind_alloc<T> 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<A>::destroy(alloc, p); + beast::detail::allocator_traits<A>::deallocate(alloc, p, 1); + }; + std::unique_ptr<T, decltype(deleter)> t{ + beast::detail::allocator_traits<A>::allocate(alloc, 1), deleter}; + beast::detail::allocator_traits<A>::construct(alloc, t.get(), + static_cast<DeducedHandler const&>(h), + std::forward<Args>(args)...); + destroy = true; + new(&h_) Handler(std::forward<DeducedHandler>(h)); + t_ = t.release(); } template<class T, class Handler> @@ -107,18 +92,16 @@ handler_ptr<T, Handler>:: release_handler() -> handler_type { - BOOST_ASSERT(p_); - BOOST_ASSERT(p_->t); - p_->t->~T(); - typename std::allocator_traits< - boost::asio::associated_allocator_t<Handler>>:: - template rebind_alloc<T> 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<class T, class Handler> @@ -127,18 +110,16 @@ void handler_ptr<T, Handler>:: invoke(Args&&... args) { - BOOST_ASSERT(p_); - BOOST_ASSERT(p_->t); - p_->t->~T(); - typename std::allocator_traits< - boost::asio::associated_allocator_t<Handler>>:: - template rebind_alloc<T> 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>(args)...); + BOOST_ASSERT(t_); + clear(); + auto deleter = [](Handler* h) + { + h->~Handler(); + }; + std::unique_ptr< + Handler, decltype(deleter)> destroyer{ + &handler(), deleter}; + handler()(std::forward<Args>(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<Allocator>::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,10 +35,31 @@ 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}; } |