From d8a23776d461f3e36b62884be11bd9abfca24cd2 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 8 Dec 2018 14:13:43 -0800 Subject: [PATCH] Tidy up experimental files --- CHANGELOG.md | 1 + .../core/detail/dynamic_buffer_ref.hpp | 99 ++++++++ .../_experimental/core/detail/flat_stream.hpp | 3 +- .../core/detail/saved_handler.hpp | 2 +- .../beast/_experimental/core/flat_stream.hpp | 23 +- .../impl/{flat_stream.ipp => flat_stream.hpp} | 73 ++++-- .../core/impl/timeout_socket.hpp | 223 +++++++++++------- .../beast/_experimental/core/ssl_stream.hpp | 10 +- .../_experimental/core/timeout_service.hpp | 2 - .../_experimental/core/timeout_socket.hpp | 13 +- .../_experimental/core/timeout_work_guard.hpp | 1 + .../beast/_experimental/http/icy_stream.hpp | 9 +- .../impl/{icy_stream.ipp => icy_stream.hpp} | 218 +++++++---------- .../boost/beast/_experimental/test/error.hpp | 5 +- .../beast/_experimental/test/fail_count.hpp | 7 +- .../test/{detail => impl}/error.hpp | 30 +-- .../impl/{fail_count.ipp => fail_count.hpp} | 11 +- .../test/impl/{error.ipp => impl/error.hpp} | 13 +- .../test/impl/{stream.ipp => stream.hpp} | 89 +++---- .../boost/beast/_experimental/test/stream.hpp | 32 ++- include/boost/beast/core/detail/buffer.hpp | 4 +- 21 files changed, 489 insertions(+), 379 deletions(-) create mode 100644 include/boost/beast/_experimental/core/detail/dynamic_buffer_ref.hpp rename include/boost/beast/_experimental/core/impl/{flat_stream.ipp => flat_stream.hpp} (92%) rename include/boost/beast/_experimental/http/impl/{icy_stream.ipp => icy_stream.hpp} (81%) rename include/boost/beast/_experimental/test/{detail => impl}/error.hpp (67%) rename include/boost/beast/_experimental/test/impl/{fail_count.ipp => fail_count.hpp} (77%) rename include/boost/beast/_experimental/test/impl/{error.ipp => impl/error.hpp} (80%) rename include/boost/beast/_experimental/test/impl/{stream.ipp => stream.hpp} (89%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35bf6257..15e3562d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Version 198: * flat_static_buffer_improvements * saved_handler maintains a work_guard (websocket) * Add buffer_traits.hpp, buffers_type +* Tidy up experimental files API Changes: diff --git a/include/boost/beast/_experimental/core/detail/dynamic_buffer_ref.hpp b/include/boost/beast/_experimental/core/detail/dynamic_buffer_ref.hpp new file mode 100644 index 00000000..12efae65 --- /dev/null +++ b/include/boost/beast/_experimental/core/detail/dynamic_buffer_ref.hpp @@ -0,0 +1,99 @@ +// +// Copyright (c) 2018 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_CORE_DETAIL_DYNAMIC_BUFFER_REF_HPP +#define BOOST_BEAST_CORE_DETAIL_DYNAMIC_BUFFER_REF_HPP + +#include +#include +#include + +namespace boost { +namespace beast { +namespace detail { + +template +class dynamic_buffer_ref +{ + DynamicBuffer& b_; + +public: + using const_buffers_type = typename + DynamicBuffer::const_buffers_type; + + using mutable_buffers_type = typename + DynamicBuffer::mutable_buffers_type; + + dynamic_buffer_ref( + dynamic_buffer_ref&&) = default; + + explicit + dynamic_buffer_ref( + DynamicBuffer& b) noexcept + : b_(b) + { + } + + std::size_t + size() const noexcept + { + return b_.size(); + } + + std::size_t + max_size() const noexcept + { + return b_.max_size(); + } + + std::size_t + capacity() const noexcept + { + return b_.capacity(); + } + + const_buffers_type + data() const noexcept + { + return b_.data(); + } + + mutable_buffers_type + prepare(std::size_t n) + { + return b_.prepare(n); + } + + void + commit(std::size_t n) + { + b_.commit(n); + } + + void + consume(std::size_t n) + { + b_.consume(n); + } +}; + +template +typename std::enable_if< + net::is_dynamic_buffer::value, + dynamic_buffer_ref>::type +ref(DynamicBuffer& b) +{ + return dynamic_buffer_ref(b); +} + +} // detail +} // beast +} // boost + +#endif diff --git a/include/boost/beast/_experimental/core/detail/flat_stream.hpp b/include/boost/beast/_experimental/core/detail/flat_stream.hpp index e86d263e..51e496f9 100644 --- a/include/boost/beast/_experimental/core/detail/flat_stream.hpp +++ b/include/boost/beast/_experimental/core/detail/flat_stream.hpp @@ -34,7 +34,8 @@ public: template static coalesce_result - coalesce(BufferSequence const& buffers, std::size_t limit) + coalesce( + BufferSequence const& buffers, std::size_t limit) { coalesce_result result{0, false}; auto first = net::buffer_sequence_begin(buffers); diff --git a/include/boost/beast/_experimental/core/detail/saved_handler.hpp b/include/boost/beast/_experimental/core/detail/saved_handler.hpp index 3fde7b5a..d1d000c8 100644 --- a/include/boost/beast/_experimental/core/detail/saved_handler.hpp +++ b/include/boost/beast/_experimental/core/detail/saved_handler.hpp @@ -41,7 +41,7 @@ class saved_handler void operator()() override { - boost::asio::dispatch(std::move(h_)); + net::dispatch(std::move(h_)); } }; diff --git a/include/boost/beast/_experimental/core/flat_stream.hpp b/include/boost/beast/_experimental/core/flat_stream.hpp index d74426bd..58fd518f 100644 --- a/include/boost/beast/_experimental/core/flat_stream.hpp +++ b/include/boost/beast/_experimental/core/flat_stream.hpp @@ -21,7 +21,7 @@ namespace boost { namespace beast { -/** Stream wrapper to improve ssl::stream write performance. +/** Stream wrapper to improve write performance. This wrapper flattens writes for buffer sequences having length greater than 1 and total size below a predefined amount, using @@ -30,6 +30,11 @@ namespace beast { which does not use OpenSSL's scatter/gather interface for its low-level read some and write some operations. + It is normally not necessary to use this class directly if you + are already using @ref ssl_stream. The following examples shows + how to use this class with the ssl stream that comes with + networking: + @par Example To use the @ref flat_stream template with SSL streams, declare @@ -37,12 +42,12 @@ namespace beast { will be forwarded to the next layer's constructor: @code - flat_stream> fs{ioc, ctx}; + flat_stream> fs{ioc, ctx}; @endcode Alternatively you can write @code ssl::stream ss{ioc, ctx}; - flat_stream&> fs{ss}; + flat_stream&> fs{ss}; @endcode The resulting stream may be passed to any stream algorithms which @@ -58,7 +63,7 @@ namespace beast { The stream may also be used as a template parameter in other stream wrappers, such as for websocket: @code - websocket::stream>> ws{ioc, ctx}; + websocket::stream>> ws{ioc, ctx}; @endcode @tparam NextLayer The type representing the next layer, to which @@ -147,7 +152,7 @@ public: stream layers. */ next_layer_type& - next_layer() + next_layer() noexcept { return stream_; } @@ -161,7 +166,7 @@ public: stream layers. */ next_layer_type const& - next_layer() const + next_layer() const noexcept { return stream_; } @@ -175,7 +180,7 @@ public: stream layers. */ lowest_layer_type& - lowest_layer() + lowest_layer() noexcept { return stream_.lowest_layer(); } @@ -189,7 +194,7 @@ public: stream layers. Ownership is not transferred to the caller. */ lowest_layer_type const& - lowest_layer() const + lowest_layer() const noexcept { return stream_.lowest_layer(); } @@ -349,6 +354,6 @@ public: } // beast } // boost -#include +#include #endif diff --git a/include/boost/beast/_experimental/core/impl/flat_stream.ipp b/include/boost/beast/_experimental/core/impl/flat_stream.hpp similarity index 92% rename from include/boost/beast/_experimental/core/impl/flat_stream.ipp rename to include/boost/beast/_experimental/core/impl/flat_stream.hpp index 0e845c5d..637433c4 100644 --- a/include/boost/beast/_experimental/core/impl/flat_stream.ipp +++ b/include/boost/beast/_experimental/core/impl/flat_stream.hpp @@ -7,8 +7,8 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_CORE_IMPL_FLAT_STREAM_IPP -#define BOOST_BEAST_CORE_IMPL_FLAT_STREAM_IPP +#ifndef BOOST_BEAST_CORE_IMPL_FLAT_STREAM_HPP +#define BOOST_BEAST_CORE_IMPL_FLAT_STREAM_HPP #include #include @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -73,36 +74,30 @@ public: { } - using allocator_type = - net::associated_allocator_t; - - allocator_type - get_allocator() const noexcept - { - return (net::get_associated_allocator)(h_); - } - - using executor_type = net::associated_executor_t< - Handler, decltype(std::declval().get_executor())>; - - executor_type - get_executor() const noexcept - { - return (net::get_associated_executor)( - h_, s_.get_executor()); - } - void operator()( boost::system::error_code ec, std::size_t bytes_transferred); - friend - bool asio_handler_is_continuation(write_op* op) + // + + using allocator_type = + net::associated_allocator_t; + + using executor_type = net::associated_executor_t< + Handler, decltype(std::declval().get_executor())>; + + allocator_type + get_allocator() const noexcept { - using net::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->h_)); + return net::get_associated_allocator(h_); + } + + executor_type + get_executor() const noexcept + { + return net::get_associated_executor( + h_, s_.get_executor()); } template @@ -112,6 +107,32 @@ public: using net::asio_handler_invoke; asio_handler_invoke(f, std::addressof(op->h_)); } + + friend + void* asio_handler_allocate( + std::size_t size, write_op* op) + { + using net::asio_handler_allocate; + return asio_handler_allocate( + size, std::addressof(op->h_)); + } + + friend + void asio_handler_deallocate( + void* p, std::size_t size, write_op* op) + { + using net::asio_handler_deallocate; + asio_handler_deallocate( + p, size, std::addressof(op->h_)); + } + + friend + bool asio_handler_is_continuation(write_op* op) + { + using net::asio_handler_is_continuation; + return asio_handler_is_continuation( + std::addressof(op->h_)); + } }; template diff --git a/include/boost/beast/_experimental/core/impl/timeout_socket.hpp b/include/boost/beast/_experimental/core/impl/timeout_socket.hpp index 1e25c8d2..d2ef676b 100644 --- a/include/boost/beast/_experimental/core/impl/timeout_socket.hpp +++ b/include/boost/beast/_experimental/core/impl/timeout_socket.hpp @@ -10,7 +10,7 @@ #ifndef BOOST_BEAST_CORE_IMPL_TIMEOUT_SOCKET_HPP #define BOOST_BEAST_CORE_IMPL_TIMEOUT_SOCKET_HPP -#include +#include #include #include #include @@ -60,43 +60,6 @@ public: s_.sock_.async_write_some(b, std::move(*this)); } - using allocator_type = - net::associated_allocator_t; - - allocator_type - get_allocator() const noexcept - { - return net::get_associated_allocator(h_); - } - - using executor_type = - net::associated_executor_t&>().get_executor())>; - - executor_type - get_executor() const noexcept - { - return net::get_associated_executor( - h_, s_.get_executor()); - } - - friend - bool asio_handler_is_continuation(async_op* op) - { - using net::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, async_op* op) - { - using net::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->h_)); - } - void operator()(error_code ec, std::size_t bytes_transferred) { @@ -111,6 +74,63 @@ public: h_(ec, bytes_transferred); } + // + + using allocator_type = + net::associated_allocator_t; + + using executor_type = + net::associated_executor_t&>().get_executor())>; + + allocator_type + get_allocator() const noexcept + { + return net::get_associated_allocator(h_); + } + + executor_type + get_executor() const noexcept + { + return net::get_associated_executor( + h_, s_.get_executor()); + } + + template + friend + void asio_handler_invoke(Function&& f, async_op* op) + { + using net::asio_handler_invoke; + asio_handler_invoke(f, std::addressof(op->h_)); + } + + friend + void* asio_handler_allocate( + std::size_t size, async_op* op) + { + using net::asio_handler_allocate; + return asio_handler_allocate( + size, std::addressof(op->h_)); + } + + friend + void asio_handler_deallocate( + void* p, std::size_t size, async_op* op) + { + using net::asio_handler_deallocate; + asio_handler_deallocate( + p, size, std::addressof(op->h_)); + } + + friend + bool asio_handler_is_continuation(async_op* op) + { + using net::asio_handler_is_continuation; + return asio_handler_is_continuation( + std::addressof(op->h_)); + } + private: Handler h_; basic_timeout_socket& s_; @@ -171,7 +191,7 @@ basic_timeout_socket:: template template BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, - void(boost::system::error_code, std::size_t)) + void(error_code, std::size_t)) basic_timeout_socket:: async_read_some( MutableBufferSequence const& buffers, @@ -192,7 +212,7 @@ async_read_some( template template BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, - void(boost::system::error_code, std::size_t)) + void(error_code, std::size_t)) basic_timeout_socket:: async_write_some( ConstBufferSequence const& buffers, @@ -240,43 +260,6 @@ public: std::move(*this)); } - using allocator_type = - net::associated_allocator_t; - - allocator_type - get_allocator() const noexcept - { - return net::get_associated_allocator(h_); - } - - using executor_type = - net::associated_executor_t&>().get_executor())>; - - executor_type - get_executor() const noexcept - { - return net::get_associated_executor( - h_, s_.get_executor()); - } - - friend - bool asio_handler_is_continuation(connect_op* op) - { - using net::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, connect_op* op) - { - using net::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->h_)); - } - template void operator()(error_code ec, Arg&& arg) @@ -292,6 +275,65 @@ public: h_(ec, std::forward(arg)); } + // + + using allocator_type = + net::associated_allocator_t; + + using executor_type = + net::associated_executor_t&>().get_executor())>; + + allocator_type + get_allocator() const noexcept + { + return net::get_associated_allocator(h_); + } + + executor_type + get_executor() const noexcept + { + return net::get_associated_executor( + h_, s_.get_executor()); + } + + template + friend + void asio_handler_invoke( + Function&& f, connect_op* op) + { + using net::asio_handler_invoke; + asio_handler_invoke( + f, std::addressof(op->h_)); + } + + friend + void* asio_handler_allocate( + std::size_t size, connect_op* op) + { + using net::asio_handler_allocate; + return asio_handler_allocate( + size, std::addressof(op->h_)); + } + + friend + void asio_handler_deallocate( + void* p, std::size_t size, connect_op* op) + { + using net::asio_handler_deallocate; + asio_handler_deallocate( + p, size, std::addressof(op->h_)); + } + + friend + bool asio_handler_is_continuation(connect_op* op) + { + using net::asio_handler_is_continuation; + return asio_handler_is_continuation( + std::addressof(op->h_)); + } + private: Handler h_; timeout_work_guard work_; @@ -304,7 +346,8 @@ struct any_endpoint { template bool - operator()(Error const&, Endpoint const&) const noexcept + operator()( + Error const&, Endpoint const&) const noexcept { return true; } @@ -344,17 +387,17 @@ template< class EndpointSequence, class RangeConnectHandler, class> BOOST_ASIO_INITFN_RESULT_TYPE(RangeConnectHandler, - void(boost::system::error_code, typename Protocol::endpoint)) + void(error_code, typename Protocol::endpoint)) async_connect( basic_timeout_socket& s, EndpointSequence const& endpoints, RangeConnectHandler&& handler) { BOOST_BEAST_HANDLER_INIT(RangeConnectHandler, - void(boost::system::error_code, typename Protocol::endpoint)); + void(error_code, typename Protocol::endpoint)); detail::connect_op( s, endpoints, detail::any_endpoint{}, std::forward(handler)); @@ -367,7 +410,7 @@ template< class ConnectCondition, class RangeConnectHandler, class> BOOST_ASIO_INITFN_RESULT_TYPE(RangeConnectHandler, - void (boost::system::error_code, typename Protocol::endpoint)) + void (error_code, typename Protocol::endpoint)) async_connect( basic_timeout_socket& s, EndpointSequence const& endpoints, @@ -375,10 +418,10 @@ async_connect( RangeConnectHandler&& handler) { BOOST_BEAST_HANDLER_INIT(RangeConnectHandler, - void(boost::system::error_code, typename Protocol::endpoint)); + void(error_code, typename Protocol::endpoint)); detail::connect_op( s, endpoints, connect_condition, std::forward(handler)); @@ -390,17 +433,17 @@ template< class Iterator, class IteratorConnectHandler, class> BOOST_ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler, - void (boost::system::error_code, Iterator)) + void (error_code, Iterator)) async_connect( basic_timeout_socket& s, Iterator begin, Iterator end, IteratorConnectHandler&& handler) { BOOST_BEAST_HANDLER_INIT(IteratorConnectHandler, - void(boost::system::error_code, Iterator)); + void(error_code, Iterator)); detail::connect_op( + void(error_code, Iterator))>( s, detail::endpoint_range(begin, end), detail::any_endpoint{}, std::forward(handler)); return init.result.get(); @@ -412,7 +455,7 @@ template< class ConnectCondition, class IteratorConnectHandler, class> BOOST_ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler, - void (boost::system::error_code, Iterator)) + void (error_code, Iterator)) async_connect( basic_timeout_socket& s, Iterator begin, Iterator end, @@ -420,10 +463,10 @@ async_connect( IteratorConnectHandler&& handler) { BOOST_BEAST_HANDLER_INIT(IteratorConnectHandler, - void(boost::system::error_code, Iterator)); + void(error_code, Iterator)); detail::connect_op( + void(error_code, Iterator))>( s, detail::endpoint_range(begin, end), connect_condition, std::forward(handler)); return init.result.get(); diff --git a/include/boost/beast/_experimental/core/ssl_stream.hpp b/include/boost/beast/_experimental/core/ssl_stream.hpp index fe2683e2..36c3640b 100644 --- a/include/boost/beast/_experimental/core/ssl_stream.hpp +++ b/include/boost/beast/_experimental/core/ssl_stream.hpp @@ -146,7 +146,7 @@ public: @endcode */ native_handle_type - native_handle() + native_handle() noexcept { return p_->next_layer().native_handle(); } @@ -163,7 +163,7 @@ public: Ownership is not transferred to the caller. */ next_layer_type const& - next_layer() const + next_layer() const noexcept { return p_->next_layer().next_layer(); } @@ -180,7 +180,7 @@ public: Ownership is not transferred to the caller. */ next_layer_type& - next_layer() + next_layer() noexcept { return p_->next_layer().next_layer(); } @@ -194,7 +194,7 @@ public: Ownership is not transferred to the caller. */ lowest_layer_type& - lowest_layer() + lowest_layer() noexcept { return p_->lowest_layer(); } @@ -208,7 +208,7 @@ public: Ownership is not transferred to the caller. */ lowest_layer_type const& - lowest_layer() const + lowest_layer() const noexcept { return p_->lowest_layer(); } diff --git a/include/boost/beast/_experimental/core/timeout_service.hpp b/include/boost/beast/_experimental/core/timeout_service.hpp index 894e6a5c..7251acdd 100644 --- a/include/boost/beast/_experimental/core/timeout_service.hpp +++ b/include/boost/beast/_experimental/core/timeout_service.hpp @@ -14,8 +14,6 @@ #include // #include #include -#include // temporary - namespace boost { namespace beast { diff --git a/include/boost/beast/_experimental/core/timeout_socket.hpp b/include/boost/beast/_experimental/core/timeout_socket.hpp index e965b3dc..69308847 100644 --- a/include/boost/beast/_experimental/core/timeout_socket.hpp +++ b/include/boost/beast/_experimental/core/timeout_socket.hpp @@ -51,16 +51,17 @@ template< class basic_timeout_socket { template class async_op; - template friend class detail::connect_op; + template + friend class detail::connect_op; Executor ex_; // must come first timeout_handle rd_timer_; timeout_handle wr_timer_; timeout_handle cn_timer_; - net::basic_stream_socket sock_; detail::saved_handler rd_op_; detail::saved_handler wr_op_; detail::saved_handler cn_op_; + net::basic_stream_socket sock_; public: /// The type of the next layer. @@ -127,7 +128,7 @@ public: stream layers. */ next_layer_type& - next_layer() + next_layer() noexcept { return sock_; } @@ -141,7 +142,7 @@ public: stream layers. */ next_layer_type const& - next_layer() const + next_layer() const noexcept { return sock_; } @@ -155,7 +156,7 @@ public: stream layers. */ lowest_layer_type& - lowest_layer() + lowest_layer() noexcept { return sock_.lowest_layer(); } @@ -169,7 +170,7 @@ public: stream layers. Ownership is not transferred to the caller. */ lowest_layer_type const& - lowest_layer() const + lowest_layer() const noexcept { return sock_.lowest_layer(); } diff --git a/include/boost/beast/_experimental/core/timeout_work_guard.hpp b/include/boost/beast/_experimental/core/timeout_work_guard.hpp index 13ce472c..9112f1e5 100644 --- a/include/boost/beast/_experimental/core/timeout_work_guard.hpp +++ b/include/boost/beast/_experimental/core/timeout_work_guard.hpp @@ -10,6 +10,7 @@ #ifndef BOOST_BEAST_CORE_TIMEOUT_WORK_GUARD_HPP #define BOOST_BEAST_CORE_TIMEOUT_WORK_GUARD_HPP +#include #include #include diff --git a/include/boost/beast/_experimental/http/icy_stream.hpp b/include/boost/beast/_experimental/http/icy_stream.hpp index 87ed0bbc..a992daf1 100644 --- a/include/boost/beast/_experimental/http/icy_stream.hpp +++ b/include/boost/beast/_experimental/http/icy_stream.hpp @@ -88,7 +88,8 @@ public: typename std::remove_reference::type; /// The type of the lowest layer. - using lowest_layer_type = boost::beast::get_lowest_layer; + using lowest_layer_type = + get_lowest_layer; /// The type of the executor associated with the object. using executor_type = typename next_layer_type::executor_type; @@ -196,7 +197,7 @@ public: @returns The number of bytes read. - @throws boost::system::system_error Thrown on failure. + @throws system_error Thrown on failure. @note The `read_some` operation may not read all of the requested number of bytes. Consider using the function `net::read` if you need to ensure @@ -272,7 +273,7 @@ public: @returns The number of bytes written. - @throws boost::system::system_error Thrown on failure. + @throws system_error Thrown on failure. @note The `write_some` operation may not transmit all of the data to the peer. Consider using the function `net::write` if you need to @@ -340,6 +341,6 @@ public: } // beast } // boost -#include +#include #endif diff --git a/include/boost/beast/_experimental/http/impl/icy_stream.ipp b/include/boost/beast/_experimental/http/impl/icy_stream.hpp similarity index 81% rename from include/boost/beast/_experimental/http/impl/icy_stream.ipp rename to include/boost/beast/_experimental/http/impl/icy_stream.hpp index 02b8c16a..1d4a135c 100644 --- a/include/boost/beast/_experimental/http/impl/icy_stream.ipp +++ b/include/boost/beast/_experimental/http/impl/icy_stream.hpp @@ -7,28 +7,24 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_CORE_IMPL_ICY_STREAM_IPP -#define BOOST_BEAST_CORE_IMPL_ICY_STREAM_IPP +#ifndef BOOST_BEAST_CORE_IMPL_ICY_STREAM_HPP +#define BOOST_BEAST_CORE_IMPL_ICY_STREAM_HPP +#include #include #include #include #include #include +#include #include -#include -#include -#include #include -#include -#include -#include -#include #include #include #include #include #include +#include #include #include @@ -38,87 +34,15 @@ namespace http { namespace detail { -template -class dynamic_buffer_ref -{ - DynamicBuffer& b_; - -public: - using const_buffers_type = - typename DynamicBuffer::const_buffers_type; - - using mutable_buffers_type = - typename DynamicBuffer::mutable_buffers_type; - - dynamic_buffer_ref(dynamic_buffer_ref&&) = default; - - explicit - dynamic_buffer_ref(DynamicBuffer& b) - : b_(b) - { - } - - std::size_t - size() const - { - return b_.size(); - } - - std::size_t - max_size() const - { - return b_.max_size(); - } - - std::size_t - capacity() const - { - return b_.capacity(); - } - - const_buffers_type - data() const - { - return b_.data(); - } - - mutable_buffers_type - prepare(std::size_t n) - { - return b_.prepare(n); - } - - void - commit(std::size_t n) - { - b_.commit(n); - } - - void - consume(std::size_t n) - { - b_.consume(n); - } -}; - -template -typename std::enable_if< - net::is_dynamic_buffer::value, - dynamic_buffer_ref>::type -ref(DynamicBuffer& b) -{ - return dynamic_buffer_ref(b); -} - template void buffer_shift(MutableBuffers const& out, ConstBuffers const& in) { - using net::buffer_size; auto in_pos = net::buffer_sequence_end(in); auto out_pos = net::buffer_sequence_end(out); auto const in_begin = net::buffer_sequence_begin(in); auto const out_begin = net::buffer_sequence_begin(out); + using net::buffer_size; BOOST_ASSERT(buffer_size(in) == buffer_size(out)); if(in_pos == in_begin || out_pos == out_begin) return; @@ -201,8 +125,8 @@ class icy_stream::read_op net::associated_allocator_t::template rebind::other; #else - std::allocator_traits> - ::template rebind_alloc; + std::allocator_traits>::template rebind_alloc; #endif struct data @@ -236,36 +160,66 @@ public: { } - using allocator_type = - net::associated_allocator_t; - - allocator_type - get_allocator() const noexcept - { - return (net::get_associated_allocator)(d_.handler()); - } - - using executor_type = net::associated_executor_t< - Handler, decltype(std::declval().get_executor())>; - - executor_type - get_executor() const noexcept - { - return (net::get_associated_executor)( - d_.handler(), d_->s.get_executor()); - } - void operator()( boost::system::error_code ec, std::size_t bytes_transferred); + // + + using allocator_type = + net::associated_allocator_t; + + using executor_type = net::associated_executor_t< + Handler, decltype(std::declval().get_executor())>; + + allocator_type + get_allocator() const noexcept + { + return net::get_associated_allocator(d_.handler()); + } + + executor_type + get_executor() const noexcept + { + return net::get_associated_executor( + d_.handler(), d_->s.get_executor()); + } + template friend - void asio_handler_invoke(Function&& f, read_op* op) + void asio_handler_invoke( + Function&& f, read_op* op) { using net::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->d_.handler())); + asio_handler_invoke( + f, std::addressof(op->d_.handler())); + } + + friend + void* asio_handler_allocate( + std::size_t size, read_op* op) + { + using net::asio_handler_allocate; + return asio_handler_allocate( + size, std::addressof(op->d_.handler())); + } + + friend + void asio_handler_deallocate( + void* p, std::size_t size, read_op* op) + { + using net::asio_handler_deallocate; + asio_handler_deallocate( + p, size, std::addressof(op->d_.handler())); + } + + friend + bool asio_handler_is_continuation(read_op* op) + { + using net::asio_handler_is_continuation; + return asio_handler_is_continuation( + std::addressof(op->d_.handler())); } }; @@ -278,10 +232,8 @@ operator()( error_code ec, std::size_t bytes_transferred) { - using net::buffer_copy; - using net::buffer_size; using iterator = net::buffers_iterator< - typename detail::dynamic_buffer_ref< + typename beast::detail::dynamic_buffer_ref< buffers_adapter>::const_buffers_type>; auto& d = *d_; BOOST_ASIO_CORO_REENTER(*this) @@ -297,7 +249,7 @@ operator()( { if(d.s.copy_ > 0) { - auto const n = buffer_copy( + auto const n = net::buffer_copy( d.b.prepare(std::min( d.s.copy_, d.b.max_size())), net::buffer(d.s.buf_)); @@ -339,7 +291,7 @@ operator()( d.s.buf_[1] != 'C' || d.s.buf_[2] != 'Y') { - buffer_copy( + net::buffer_copy( d.b.value(), net::buffer(d.s.buf_, n)); if(d.b.max_size() < 3) @@ -369,7 +321,7 @@ operator()( BOOST_ASIO_CORO_YIELD net::async_read_until( d.s.next_layer(), - detail::ref(d.b), + beast::detail::ref(d.b), detail::match_icy(d.match), std::move(*this)); if(ec) @@ -395,9 +347,9 @@ operator()( boost::in_place_init, d.b.value()); dest.consume(5); detail::buffer_shift( - buffers_prefix(n, dest), - buffers_prefix(n, d.b.value())); - buffer_copy(d.b.value(), icy_stream::version()); + beast::buffers_prefix(n, dest), + beast::buffers_prefix(n, d.b.value())); + net::buffer_copy(d.b.value(), icy_stream::version()); n += 5; bytes_transferred = n; } @@ -423,7 +375,7 @@ std::size_t icy_stream:: read_some(MutableBufferSequence const& buffers) { - static_assert(boost::beast::is_sync_read_stream::value, + static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); static_assert(net::is_mutable_buffer_sequence< MutableBufferSequence>::value, @@ -431,7 +383,7 @@ read_some(MutableBufferSequence const& buffers) error_code ec; auto n = read_some(buffers, ec); if(ec) - BOOST_THROW_EXCEPTION(boost::system::system_error{ec}); + BOOST_THROW_EXCEPTION(system_error{ec}); return n; } @@ -441,27 +393,25 @@ std::size_t icy_stream:: read_some(MutableBufferSequence const& buffers, error_code& ec) { - static_assert(boost::beast::is_sync_read_stream::value, + static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); static_assert(net::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); - using net::buffer_copy; - using net::buffer_size; using iterator = net::buffers_iterator< - typename detail::dynamic_buffer_ref< + typename beast::detail::dynamic_buffer_ref< buffers_adapter>::const_buffers_type>; buffers_adapter b(buffers); if(b.max_size() == 0) { - ec.assign(0, ec.category()); + ec = {}; return 0; } if(! detect_) { if(copy_ > 0) { - auto const n = buffer_copy( + auto const n = net::buffer_copy( b.prepare(std::min( copy_, b.max_size())), net::buffer(buf_)); @@ -495,7 +445,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec) buf_[1] != 'C' || buf_[2] != 'Y') { - buffer_copy( + net::buffer_copy( buffers, net::buffer(buf_, n)); if(b.max_size() < 3) @@ -508,13 +458,14 @@ read_some(MutableBufferSequence const& buffers, error_code& ec) copy_); } - return (std::min)(n, b.max_size()); + return std::min( + n, b.max_size()); } copy_ = static_cast( - buffer_copy( + net::buffer_copy( net::buffer(buf_), version() + b.max_size())); - return buffer_copy( + return net::buffer_copy( buffers, version()); } @@ -522,7 +473,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec) bool match = false; auto n = net::read_until( stream_, - detail::ref(b), + beast::detail::ref(b), detail::match_icy(match), ec); if(ec) @@ -547,7 +498,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec) detail::buffer_shift( buffers_prefix(n, dest), buffers_prefix(n, buffers)); - buffer_copy(buffers, version()); + net::buffer_copy(buffers, version()); n += 5; return n; } @@ -563,7 +514,7 @@ async_read_some( MutableBufferSequence const& buffers, ReadHandler&& handler) { - static_assert(boost::beast::is_async_read_stream::value, + static_assert(is_async_read_stream::value, "AsyncReadStream requirements not met"); static_assert(net::is_mutable_buffer_sequence< MutableBufferSequence >::value, @@ -585,7 +536,7 @@ std::size_t icy_stream:: write_some(MutableBufferSequence const& buffers) { - static_assert(boost::beast::is_sync_write_stream::value, + static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); static_assert(net::is_const_buffer_sequence< MutableBufferSequence>::value, @@ -599,7 +550,7 @@ std::size_t icy_stream:: write_some(MutableBufferSequence const& buffers, error_code& ec) { - static_assert(boost::beast::is_sync_write_stream::value, + static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); static_assert(net::is_const_buffer_sequence< MutableBufferSequence>::value, @@ -618,12 +569,13 @@ async_write_some( MutableBufferSequence const& buffers, WriteHandler&& handler) { - static_assert(boost::beast::is_async_write_stream::value, + static_assert(is_async_write_stream::value, "AsyncWriteStream requirements not met"); static_assert(net::is_const_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); - return stream_.async_write_some(buffers, std::forward(handler)); + return stream_.async_write_some( + buffers, std::forward(handler)); } } // http diff --git a/include/boost/beast/_experimental/test/error.hpp b/include/boost/beast/_experimental/test/error.hpp index 5e298b51..38339ebd 100644 --- a/include/boost/beast/_experimental/test/error.hpp +++ b/include/boost/beast/_experimental/test/error.hpp @@ -10,8 +10,7 @@ #ifndef BOOST_BEAST_TEST_ERROR_HPP #define BOOST_BEAST_TEST_ERROR_HPP -#include -#include +#include namespace boost { namespace beast { @@ -32,6 +31,6 @@ enum class error } // beast } // boost -#include +#include #endif diff --git a/include/boost/beast/_experimental/test/fail_count.hpp b/include/boost/beast/_experimental/test/fail_count.hpp index aee7f60d..5317b754 100644 --- a/include/boost/beast/_experimental/test/fail_count.hpp +++ b/include/boost/beast/_experimental/test/fail_count.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include namespace boost { namespace beast { @@ -42,16 +42,19 @@ public: @param n The 0-based index of the operation to fail on or after @param ev An optional error code to use when generating a simulated failure */ + BOOST_BEAST_DECL explicit fail_count( std::size_t n, error_code ev = make_error_code(error::test_failure)); /// Throw an exception on the Nth failure + BOOST_BEAST_DECL void fail(); /// Set an error code on the Nth failure + BOOST_BEAST_DECL bool fail(error_code& ec); }; @@ -60,6 +63,6 @@ public: } // beast } // boost -#include +#include #endif diff --git a/include/boost/beast/_experimental/test/detail/error.hpp b/include/boost/beast/_experimental/test/impl/error.hpp similarity index 67% rename from include/boost/beast/_experimental/test/detail/error.hpp rename to include/boost/beast/_experimental/test/impl/error.hpp index d8ffbc13..d0fd2209 100644 --- a/include/boost/beast/_experimental/test/detail/error.hpp +++ b/include/boost/beast/_experimental/test/impl/error.hpp @@ -7,54 +7,56 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_TEST_DETAIL_ERROR_HPP -#define BOOST_BEAST_TEST_DETAIL_ERROR_HPP +#ifndef BOOST_BEAST_TEST_IMPL_ERROR_HPP +#define BOOST_BEAST_TEST_IMPL_ERROR_HPP #include #include +#include namespace boost { - -namespace beast { -namespace test { -enum class error; -} // test -} // beast - namespace system { template<> -struct is_error_code_enum +struct is_error_code_enum< + boost::beast::test::error> + : std::true_type { - static bool const value = true; }; - } // system +} // boost +namespace boost { namespace beast { namespace test { + namespace detail { class error_codes : public error_category { public: + BOOST_BEAST_DECL const char* name() const noexcept override; + BOOST_BEAST_DECL std::string message(int ev) const override; + BOOST_BEAST_DECL error_condition default_error_condition(int ev) const noexcept override; }; } // detail +BOOST_BEAST_DECL error_code -make_error_code(error e); +make_error_code(error e) noexcept; } // test } // beast - } // boost +#include + #endif diff --git a/include/boost/beast/_experimental/test/impl/fail_count.ipp b/include/boost/beast/_experimental/test/impl/fail_count.hpp similarity index 77% rename from include/boost/beast/_experimental/test/impl/fail_count.ipp rename to include/boost/beast/_experimental/test/impl/fail_count.hpp index bc18e946..c036cdf4 100644 --- a/include/boost/beast/_experimental/test/impl/fail_count.ipp +++ b/include/boost/beast/_experimental/test/impl/fail_count.hpp @@ -7,18 +7,15 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP -#define BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP +#ifndef BOOST_BEAST_TEST_IMPL_FAIL_COUNT_HPP +#define BOOST_BEAST_TEST_IMPL_FAIL_COUNT_HPP -#include -#include #include namespace boost { namespace beast { namespace test { -inline fail_count:: fail_count( std::size_t n, @@ -28,7 +25,6 @@ fail_count( { } -inline void fail_count:: fail() @@ -39,7 +35,6 @@ fail() BOOST_THROW_EXCEPTION(system_error{ec_}); } -inline bool fail_count:: fail(error_code& ec) @@ -51,7 +46,7 @@ fail(error_code& ec) ec = ec_; return true; } - ec.assign(0, ec.category()); + ec = {}; return false; } diff --git a/include/boost/beast/_experimental/test/impl/error.ipp b/include/boost/beast/_experimental/test/impl/impl/error.hpp similarity index 80% rename from include/boost/beast/_experimental/test/impl/error.ipp rename to include/boost/beast/_experimental/test/impl/impl/error.hpp index 285947df..c81fed56 100644 --- a/include/boost/beast/_experimental/test/impl/error.ipp +++ b/include/boost/beast/_experimental/test/impl/impl/error.hpp @@ -7,8 +7,8 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_TEST_IMPL_ERROR_IPP -#define BOOST_BEAST_TEST_IMPL_ERROR_IPP +#ifndef BOOST_BEAST_TEST_IMPL_IMPL_ERROR_HPP +#define BOOST_BEAST_TEST_IMPL_IMPL_ERROR_HPP namespace boost { namespace beast { @@ -16,7 +16,6 @@ namespace test { namespace detail { -inline const char* error_codes:: name() const noexcept @@ -24,7 +23,6 @@ name() const noexcept return "boost.beast.test"; } -inline std::string error_codes:: message(int ev) const @@ -32,11 +30,11 @@ message(int ev) const switch(static_cast(ev)) { default: - case error::test_failure: return "The test stream generated a simulated error"; + case error::test_failure: return + "The test stream generated a simulated error"; } } -inline error_condition error_codes:: default_error_condition(int ev) const noexcept @@ -46,9 +44,8 @@ default_error_condition(int ev) const noexcept } // detail -inline error_code -make_error_code(error e) +make_error_code(error e) noexcept { static detail::error_codes const cat{}; return error_code{static_cast< diff --git a/include/boost/beast/_experimental/test/impl/stream.ipp b/include/boost/beast/_experimental/test/impl/stream.hpp similarity index 89% rename from include/boost/beast/_experimental/test/impl/stream.ipp rename to include/boost/beast/_experimental/test/impl/stream.hpp index caaf86d8..c4e47107 100644 --- a/include/boost/beast/_experimental/test/impl/stream.ipp +++ b/include/boost/beast/_experimental/test/impl/stream.hpp @@ -7,16 +7,16 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_TEST_IMPL_STREAM_IPP -#define BOOST_BEAST_TEST_IMPL_STREAM_IPP +#ifndef BOOST_BEAST_TEST_IMPL_STREAM_HPP +#define BOOST_BEAST_TEST_IMPL_STREAM_HPP +#include #include namespace boost { namespace beast { namespace test { -inline stream:: ~stream() { @@ -36,7 +36,6 @@ stream:: } } -inline stream:: stream(stream&& other) { @@ -47,7 +46,6 @@ stream(stream&& other) other.in_ = in; } -inline stream& stream:: operator=(stream&& other) @@ -60,14 +58,12 @@ operator=(stream&& other) return *this; } -inline stream:: stream(net::io_context& ioc) : in_(std::make_shared(ioc, nullptr)) { } -inline stream:: stream( net::io_context& ioc, @@ -76,21 +72,17 @@ stream( { } -inline stream:: stream( net::io_context& ioc, string_view s) : in_(std::make_shared(ioc, nullptr)) { - using net::buffer; - using net::buffer_copy; - in_->b.commit(buffer_copy( + in_->b.commit(net::buffer_copy( in_->b.prepare(s.size()), - buffer(s.data(), s.size()))); + net::buffer(s.data(), s.size()))); } -inline stream:: stream( net::io_context& ioc, @@ -98,14 +90,11 @@ stream( string_view s) : in_(std::make_shared(ioc, &fc)) { - using net::buffer; - using net::buffer_copy; - in_->b.commit(buffer_copy( + in_->b.commit(net::buffer_copy( in_->b.prepare(s.size()), - buffer(s.data(), s.size()))); + net::buffer(s.data(), s.size()))); } -inline void stream:: connect(stream& remote) @@ -115,32 +104,29 @@ connect(stream& remote) out_ = remote.in_; remote.out_ = in_; } -inline + string_view stream:: str() const { auto const bs = in_->b.data(); - if(net::buffer_size(bs) == 0) + using net::buffer_size; + if(buffer_size(bs) == 0) return {}; - auto const b = buffers_front(bs); + auto const b = beast::buffers_front(bs); return {static_cast(b.data()), b.size()}; } -inline void stream:: append(string_view s) { - using net::buffer; - using net::buffer_copy; std::lock_guard lock{in_->m}; - in_->b.commit(buffer_copy( + in_->b.commit(net::buffer_copy( in_->b.prepare(s.size()), - buffer(s.data(), s.size()))); + net::buffer(s.data(), s.size()))); } -inline void stream:: clear() @@ -149,7 +135,6 @@ clear() in_->b.consume(in_->b.size()); } -inline void stream:: close() @@ -166,7 +151,6 @@ close() } } -inline void stream:: close_remote() @@ -203,10 +187,9 @@ read_some(MutableBufferSequence const& buffers, static_assert(net::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); - using net::buffer_copy; - using net::buffer_size; if(in_->fc && in_->fc->fail(ec)) return 0; + using net::buffer_size; if(buffer_size(buffers) == 0) { ec.clear(); @@ -224,8 +207,8 @@ read_some(MutableBufferSequence const& buffers, std::size_t bytes_transferred; if(in_->b.size() > 0) { - ec.assign(0, ec.category()); - bytes_transferred = buffer_copy( + ec = {}; + bytes_transferred = net::buffer_copy( buffers, in_->b.data(), in_->read_max); in_->b.consume(bytes_transferred); } @@ -253,11 +236,8 @@ async_read_some( static_assert(net::is_mutable_buffer_sequence< MutableBufferSequence>::value, "MutableBufferSequence requirements not met"); - using net::buffer_copy; - using net::buffer_size; BOOST_BEAST_HANDLER_INIT( ReadHandler, void(error_code, std::size_t)); - error_code ec; if(in_->fc && in_->fc->fail(ec)) { @@ -272,10 +252,11 @@ async_read_some( { std::unique_lock lock{in_->m}; BOOST_ASSERT(! in_->op); - if(buffer_size(buffers) == 0 || + using net::buffer_size; + if( buffer_size(buffers) == 0 || buffer_size(in_->b.data()) > 0) { - auto const bytes_transferred = buffer_copy( + auto const bytes_transferred = net::buffer_copy( buffers, in_->b.data(), in_->read_max); in_->b.consume(bytes_transferred); lock.unlock(); @@ -338,8 +319,6 @@ write_some( static_assert(net::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - using net::buffer_copy; - using net::buffer_size; auto out = out_.lock(); if(! out) { @@ -349,16 +328,17 @@ write_some( BOOST_ASSERT(out->code == status::ok); if(in_->fc && in_->fc->fail(ec)) return 0; - auto const n = (std::min)( + using net::buffer_size; + auto const n = std::min( buffer_size(buffers), in_->write_max); std::unique_lock lock{out->m}; auto const bytes_transferred = - buffer_copy(out->b.prepare(n), buffers); + net::buffer_copy(out->b.prepare(n), buffers); out->b.commit(bytes_transferred); out->on_write(); lock.unlock(); ++in_->nwrite; - ec.assign(0, ec.category()); + ec = {}; return bytes_transferred; } @@ -372,8 +352,6 @@ async_write_some(ConstBufferSequence const& buffers, static_assert(net::is_const_buffer_sequence< ConstBufferSequence>::value, "ConstBufferSequence requirements not met"); - using net::buffer_copy; - using net::buffer_size; BOOST_BEAST_HANDLER_INIT( WriteHandler, void(error_code, std::size_t)); auto out = out_.lock(); @@ -401,11 +379,12 @@ async_write_some(ConstBufferSequence const& buffers, } else { - auto const n = - (std::min)(buffer_size(buffers), in_->write_max); + using net::buffer_size; + auto const n = std::min( + buffer_size(buffers), in_->write_max); std::unique_lock lock{out->m}; auto const bytes_transferred = - buffer_copy(out->b.prepare(n), buffers); + net::buffer_copy(out->b.prepare(n), buffers); out->b.commit(bytes_transferred); out->on_write(); lock.unlock(); @@ -422,7 +401,6 @@ async_write_some(ConstBufferSequence const& buffers, return init.result.get(); } -inline void teardown( websocket::role_type, @@ -439,11 +417,10 @@ boost::system::error_code& ec) s.in_->fc->fail(ec)) ec = net::error::eof; else - ec.assign(0, ec.category()); + ec = {}; } template -inline void async_teardown( websocket::role_type, @@ -461,7 +438,7 @@ TeardownHandler&& handler) s.in_->fc->fail(ec)) ec = net::error::eof; else - ec.assign(0, ec.category()); + ec = {}; net::post( s.get_executor(), @@ -506,14 +483,13 @@ class stream::read_op : public stream::read_op_base void operator()() { - using net::buffer_copy; - using net::buffer_size; std::unique_lock lock{s_.m}; BOOST_ASSERT(! s_.op); if(s_.b.size() > 0) { - auto const bytes_transferred = buffer_copy( - b_, s_.b.data(), s_.read_max); + auto const bytes_transferred = + net::buffer_copy( + b_, s_.b.data(), s_.read_max); s_.b.consume(bytes_transferred); auto& s = s_; Handler h{std::move(h_)}; @@ -561,7 +537,6 @@ public: } }; -inline stream connect(stream& to) { diff --git a/include/boost/beast/_experimental/test/stream.hpp b/include/boost/beast/_experimental/test/stream.hpp index fa2ef6dd..ee5a89b5 100644 --- a/include/boost/beast/_experimental/test/stream.hpp +++ b/include/boost/beast/_experimental/test/stream.hpp @@ -178,6 +178,7 @@ public: the peer will see the error `net::error::connection_reset` when performing any reads or writes. */ + BOOST_BEAST_DECL ~stream(); /** Move Constructor @@ -185,6 +186,7 @@ public: Moving the stream while asynchronous operations are pending results in undefined behavior. */ + BOOST_BEAST_DECL stream(stream&& other); /** Move Assignment @@ -192,6 +194,7 @@ public: Moving the stream while asynchronous operations are pending results in undefined behavior. */ + BOOST_BEAST_DECL stream& operator=(stream&& other); @@ -202,6 +205,7 @@ public: @param ioc The `io_context` object that the stream will use to dispatch handlers for any asynchronous operations. */ + BOOST_BEAST_DECL explicit stream(net::io_context& ioc); @@ -217,6 +221,7 @@ public: fail count. When the fail count reaches its internal limit, a simulated failure error will be raised. */ + BOOST_BEAST_DECL stream( net::io_context& ioc, fail_count& fc); @@ -231,6 +236,7 @@ public: @param s A string which will be appended to the input area, not including the null terminator. */ + BOOST_BEAST_DECL stream( net::io_context& ioc, string_view s); @@ -250,12 +256,14 @@ public: @param s A string which will be appended to the input area, not including the null terminator. */ + BOOST_BEAST_DECL stream( net::io_context& ioc, fail_count& fc, string_view s); /// Establish a connection + BOOST_BEAST_DECL void connect(stream& remote); @@ -279,7 +287,7 @@ public: stream layers. */ lowest_layer_type& - lowest_layer() + lowest_layer() noexcept { return *this; } @@ -293,54 +301,57 @@ public: stream layers. Ownership is not transferred to the caller. */ lowest_layer_type const& - lowest_layer() const + lowest_layer() const noexcept { return *this; } /// Set the maximum number of bytes returned by read_some void - read_size(std::size_t n) + read_size(std::size_t n) noexcept { in_->read_max = n; } /// Set the maximum number of bytes returned by write_some void - write_size(std::size_t n) + write_size(std::size_t n) noexcept { in_->write_max = n; } /// Direct input buffer access buffer_type& - buffer() + buffer() noexcept { return in_->b; } /// Returns a string view representing the pending input data + BOOST_BEAST_DECL string_view str() const; /// Appends a string to the pending input data + BOOST_BEAST_DECL void append(string_view s); /// Clear the pending input area + BOOST_BEAST_DECL void clear(); /// Return the number of reads std::size_t - nread() const + nread() const noexcept { return in_->nread; } /// Return the number of writes std::size_t - nwrite() const + nwrite() const noexcept { return in_->nwrite; } @@ -350,6 +361,7 @@ public: The other end of the connection will see `error::eof` after reading all the remaining data. */ + BOOST_BEAST_DECL void close(); @@ -358,6 +370,7 @@ public: This end of the connection will see `error::eof` after reading all the remaining data. */ + BOOST_BEAST_DECL void close_remote(); @@ -504,6 +517,7 @@ public: #if ! BOOST_BEAST_DOXYGEN friend + BOOST_BEAST_DECL void teardown( websocket::role_type, @@ -512,6 +526,7 @@ public: template friend + BOOST_BEAST_DECL void async_teardown( websocket::role_type role, @@ -534,6 +549,7 @@ stream connect(stream& to, Args&&... args); #else +BOOST_BEAST_DECL stream connect(stream& to); @@ -546,6 +562,6 @@ connect(stream& to, Arg1&& arg1, ArgN&&... argn); } // beast } // boost -#include +#include #endif diff --git a/include/boost/beast/core/detail/buffer.hpp b/include/boost/beast/core/detail/buffer.hpp index d359d100..5efbae6d 100644 --- a/include/boost/beast/core/detail/buffer.hpp +++ b/include/boost/beast/core/detail/buffer.hpp @@ -39,7 +39,7 @@ dynamic_buffer_prepare_noexcept( boost::optional result; result.emplace(buffer.prepare(size)); - ec.assign(0, ec.category()); + ec = {}; return result; } @@ -61,7 +61,7 @@ dynamic_buffer_prepare( boost::optional result; result.emplace(buffer.prepare(size)); - ec.assign(0, ec.category()); + ec = {}; return result; } catch(std::length_error const&)