mirror of
https://github.com/boostorg/beast.git
synced 2025-08-02 14:24:31 +02:00
allocate & invoke hooks are removed.
This commit is contained in:
committed by
Mohammad Nejati
parent
a7927988ea
commit
3996cae768
@@ -50,8 +50,8 @@ composed operations:
|
||||
This class is designed to be used as a base class when authoring
|
||||
composed asynchronous operations expressed as an intermediate
|
||||
completion handler. This eliminates the need for the extensive
|
||||
boilerplate to propagate the associated executor, associated
|
||||
allocator, and legacy completion handler hooks.
|
||||
boilerplate to propagate the associated executor and the associated
|
||||
allocator.
|
||||
]]
|
||||
[[
|
||||
[link beast.ref.boost__beast__allocate_stable `allocate_stable`]
|
||||
|
@@ -34,7 +34,7 @@ The implementation strategy is to make the composed object meet the
|
||||
requirements of a completion handler by being movable, and by making it
|
||||
invocable so it can be used as a continuation for the asynchronous operations
|
||||
it launches. Rather than using `std::bind` or `boost::bind`, which destroys
|
||||
the type information and therefore breaks the allocation and invocation hooks,
|
||||
the type information and therefore breaks the associators,
|
||||
we will simply pass `std::move(*this)` as the completion handler parameter for
|
||||
any operations that we initiate. For the move to work correctly, care must be
|
||||
taken to ensure that no access to data members are made after the move takes
|
||||
|
@@ -118,7 +118,7 @@ access. In contrast, Beast does not use mutexes anywhere in its
|
||||
implementation. Instead, it follows the Asio pattern. Calls to
|
||||
asynchronous initiation functions use the same method to invoke
|
||||
intermediate handlers as the method used to invoke the final handler,
|
||||
through the __asio_handler_invoke__ mechanism.
|
||||
through the associated executor mechanism.
|
||||
|
||||
The only requirement in Beast is that calls to asynchronous initiation
|
||||
functions are made from the same implicit or explicit strand. For
|
||||
@@ -131,14 +131,6 @@ costs associated with mutexes are incurred.
|
||||
[[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/impl/read_frame_op.ipp#L118 Beast]]
|
||||
[[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/transport/iostream/connection.hpp#L706 websocketpp]]
|
||||
][
|
||||
[```
|
||||
template <class Function>
|
||||
friend
|
||||
void asio_handler_invoke(Function&& f, read_frame_op* op)
|
||||
{
|
||||
return boost_asio_handler_invoke_helpers::invoke(f, op->d_->h);
|
||||
}
|
||||
```]
|
||||
[```
|
||||
mutex_type m_read_mutex;
|
||||
```]
|
||||
@@ -156,9 +148,9 @@ Boost.Asio. They are function objects which can be copied or moved but
|
||||
most importantly they are not type erased. The compiler can see
|
||||
through the type directly to the implementation, permitting
|
||||
optimization. Furthermore, Beast follows the Asio rules for treatment
|
||||
of handlers. It respects any allocation, continuation, or invocation
|
||||
customizations associated with the handler through the use of argument
|
||||
dependent lookup overloads of functions such as `asio_handler_allocate`.
|
||||
of handlers. It respects any allocation, executors, cancellations
|
||||
associated with the handler through the use of argument
|
||||
dependent lookup overloads of functions such as `bind_allocaotr`.
|
||||
|
||||
The Beast completion handler is provided at the call site. For each
|
||||
call to an asynchronous initiation function, it is guaranteed that
|
||||
|
@@ -43,8 +43,6 @@
|
||||
|
||||
[/ Networking Identifiers ]
|
||||
|
||||
[def __asio_handler_allocate__ [@boost:/doc/html/boost_asio/reference/asio_handler_allocate.html `asio_handler_allocate`]]
|
||||
[def __asio_handler_invoke__ [@boost:/doc/html/boost_asio/reference/asio_handler_invoke.html `asio_handler_invoke`]]
|
||||
[def __basic_stream_socket__ [@boost:/doc/html/boost_asio/reference/basic_stream_socket.html `basic_stream_socket`]]
|
||||
[def __const_buffer__ [@boost:/doc/html/boost_asio/reference/const_buffer.html `const_buffer`]]
|
||||
[def __deduced__ [@boost:/doc/html/boost_asio/reference/asynchronous_operations.html#boost_asio.reference.asynchronous_operations.automatic_deduction_of_initiating_function_return_type ['DEDUCED]]]
|
||||
|
@@ -196,7 +196,7 @@
|
||||
* The API to Asio has undergone changes. Please refer to the Asio release notes for details.
|
||||
|
||||
* Beast has been updated to track and respect developer choices in the use of Asio. In particular:
|
||||
* Define `BOOST_ASIO_NO_DEPRECATED` to disallow deprecated invocation and allocation hooks.
|
||||
* Define `BOOST_ASIO_NO_DEPRECATED` to disallow deprecated invocation hooks.
|
||||
* Define `BOOST_ASIO_NO_TS_EXECUTORS` to ensure that executors conform to the
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0443r11.html Standard Executors] proposal.
|
||||
* Define `BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT` to select
|
||||
|
@@ -20,9 +20,7 @@
|
||||
#include <boost/asio/associated_executor.hpp>
|
||||
#include <boost/asio/associated_immediate_executor.hpp>
|
||||
#include <boost/asio/bind_executor.hpp>
|
||||
#include <boost/asio/handler_alloc_hook.hpp>
|
||||
#include <boost/asio/handler_continuation_hook.hpp>
|
||||
#include <boost/asio/handler_invoke_hook.hpp>
|
||||
#include <boost/asio/dispatch.hpp>
|
||||
#include <boost/asio/post.hpp>
|
||||
#include <boost/core/exchange.hpp>
|
||||
@@ -63,11 +61,7 @@ namespace beast {
|
||||
shall be maintained until either the final handler is invoked, or the
|
||||
operation base is destroyed, whichever comes first.
|
||||
|
||||
@li Calls to the legacy customization points
|
||||
`asio_handler_invoke`,
|
||||
`asio_handler_allocate`,
|
||||
`asio_handler_deallocate`, and
|
||||
`asio_handler_is_continuation`,
|
||||
@li Calls to the legacy customization point `asio_handler_is_continuation`
|
||||
which use argument-dependent lookup, will be forwarded to the
|
||||
legacy customization points associated with the handler.
|
||||
|
||||
@@ -506,13 +500,6 @@ public:
|
||||
shall be maintained until either the final handler is invoked, or the
|
||||
operation base is destroyed, whichever comes first.
|
||||
|
||||
@li Calls to the legacy customization points
|
||||
`asio_handler_invoke`,
|
||||
`asio_handler_allocate`,
|
||||
`asio_handler_deallocate`, and
|
||||
`asio_handler_is_continuation`,
|
||||
which use argument-dependent lookup, will be forwarded to the
|
||||
legacy customization points associated with the handler.
|
||||
|
||||
Data members of composed operations implemented as completion handlers
|
||||
do not have stable addresses, as the composed operation object is move
|
||||
|
@@ -77,31 +77,6 @@ public:
|
||||
net::cancellation_slot());
|
||||
}
|
||||
|
||||
// The allocation hooks are still defined because they trivially forward to
|
||||
// user hooks. Forward here ensures that the user will get a compile error
|
||||
// if they build their code with BOOST_ASIO_NO_DEPRECATED.
|
||||
|
||||
friend
|
||||
boost::asio::asio_handler_allocate_is_deprecated
|
||||
asio_handler_allocate(
|
||||
std::size_t size, bind_default_executor_wrapper* p)
|
||||
{
|
||||
using boost::asio::asio_handler_allocate;
|
||||
return asio_handler_allocate(
|
||||
size, std::addressof(p->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
boost::asio::asio_handler_deallocate_is_deprecated
|
||||
asio_handler_deallocate(
|
||||
void* mem, std::size_t size,
|
||||
bind_default_executor_wrapper* p)
|
||||
{
|
||||
using boost::asio::asio_handler_deallocate;
|
||||
return asio_handler_deallocate(mem, size,
|
||||
std::addressof(p->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
bool asio_handler_is_continuation(
|
||||
bind_default_executor_wrapper* p)
|
||||
|
@@ -15,9 +15,7 @@
|
||||
#include <boost/asio/associated_allocator.hpp>
|
||||
#include <boost/asio/associated_cancellation_slot.hpp>
|
||||
#include <boost/asio/associated_executor.hpp>
|
||||
#include <boost/asio/handler_alloc_hook.hpp>
|
||||
#include <boost/asio/handler_continuation_hook.hpp>
|
||||
#include <boost/asio/handler_invoke_hook.hpp>
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <boost/mp11/integer_sequence.hpp>
|
||||
#include <boost/bind/std_placeholders.hpp>
|
||||
@@ -160,16 +158,6 @@ public:
|
||||
|
||||
//
|
||||
|
||||
template<class Function>
|
||||
friend
|
||||
boost::asio::asio_handler_invoke_is_deprecated
|
||||
asio_handler_invoke(
|
||||
Function&& f, bind_wrapper* op)
|
||||
{
|
||||
using boost::asio::asio_handler_invoke;
|
||||
return asio_handler_invoke(f, std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
bool asio_handler_is_continuation(
|
||||
bind_wrapper* op)
|
||||
@@ -178,26 +166,6 @@ public:
|
||||
return asio_handler_is_continuation(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
boost::asio::asio_handler_allocate_is_deprecated
|
||||
asio_handler_allocate(
|
||||
std::size_t size, bind_wrapper* op)
|
||||
{
|
||||
using boost::asio::asio_handler_allocate;
|
||||
return asio_handler_allocate(
|
||||
size, std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
boost::asio::asio_handler_deallocate_is_deprecated
|
||||
asio_handler_deallocate(
|
||||
void* p, std::size_t size, bind_wrapper* op)
|
||||
{
|
||||
using boost::asio::asio_handler_deallocate;
|
||||
return asio_handler_deallocate(
|
||||
p, size, std::addressof(op->h_));
|
||||
}
|
||||
};
|
||||
|
||||
template<class Handler, class... Args>
|
||||
@@ -277,16 +245,6 @@ public:
|
||||
|
||||
//
|
||||
|
||||
template<class Function>
|
||||
friend
|
||||
boost::asio::asio_handler_invoke_is_deprecated
|
||||
asio_handler_invoke(
|
||||
Function&& f, bind_front_wrapper* op)
|
||||
{
|
||||
using boost::asio::asio_handler_invoke;
|
||||
return asio_handler_invoke(f, std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
bool asio_handler_is_continuation(
|
||||
bind_front_wrapper* op)
|
||||
@@ -295,26 +253,6 @@ public:
|
||||
return asio_handler_is_continuation(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
boost::asio::asio_handler_allocate_is_deprecated
|
||||
asio_handler_allocate(
|
||||
std::size_t size, bind_front_wrapper* op)
|
||||
{
|
||||
using boost::asio::asio_handler_allocate;
|
||||
return asio_handler_allocate(
|
||||
size, std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
boost::asio::asio_handler_deallocate_is_deprecated
|
||||
asio_handler_deallocate(
|
||||
void* p, std::size_t size, bind_front_wrapper* op)
|
||||
{
|
||||
using boost::asio::asio_handler_deallocate;
|
||||
return asio_handler_deallocate(
|
||||
p, size, std::addressof(op->h_));
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
@@ -50,48 +50,6 @@ struct allocate_stable_state final
|
||||
|
||||
} // detail
|
||||
|
||||
template<
|
||||
class Handler,
|
||||
class Executor1,
|
||||
class Allocator,
|
||||
class Function>
|
||||
boost::asio::asio_handler_invoke_is_deprecated
|
||||
asio_handler_invoke(
|
||||
Function&& f,
|
||||
async_base<Handler, Executor1, Allocator>* p)
|
||||
{
|
||||
using boost::asio::asio_handler_invoke;
|
||||
return asio_handler_invoke(f,
|
||||
p->get_legacy_handler_pointer());
|
||||
}
|
||||
|
||||
template<
|
||||
class Handler,
|
||||
class Executor1,
|
||||
class Allocator>
|
||||
boost::asio::asio_handler_allocate_is_deprecated
|
||||
asio_handler_allocate(
|
||||
std::size_t size,
|
||||
async_base<Handler, Executor1, Allocator>* p)
|
||||
{
|
||||
using boost::asio::asio_handler_allocate;
|
||||
return asio_handler_allocate(size,
|
||||
p->get_legacy_handler_pointer());
|
||||
}
|
||||
|
||||
template<
|
||||
class Handler,
|
||||
class Executor1,
|
||||
class Allocator>
|
||||
boost::asio::asio_handler_deallocate_is_deprecated
|
||||
asio_handler_deallocate(
|
||||
void* mem, std::size_t size,
|
||||
async_base<Handler, Executor1, Allocator>* p)
|
||||
{
|
||||
using boost::asio::asio_handler_deallocate;
|
||||
return asio_handler_deallocate(mem, size,
|
||||
p->get_legacy_handler_pointer());
|
||||
}
|
||||
|
||||
template<
|
||||
class Handler,
|
||||
|
@@ -14,9 +14,7 @@
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/asio/associated_allocator.hpp>
|
||||
#include <boost/asio/associated_executor.hpp>
|
||||
#include <boost/asio/handler_alloc_hook.hpp>
|
||||
#include <boost/asio/handler_continuation_hook.hpp>
|
||||
#include <boost/asio/handler_invoke_hook.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
@@ -128,33 +126,6 @@ struct legacy_handler
|
||||
test(F const& f)
|
||||
{
|
||||
#if !defined(BOOST_ASIO_NO_DEPRECATED)
|
||||
{
|
||||
bool hook_invoked = false;
|
||||
bool lambda_invoked = false;
|
||||
auto h = f(legacy_handler{hook_invoked});
|
||||
using net::asio_handler_invoke;
|
||||
asio_handler_invoke(
|
||||
[&lambda_invoked]
|
||||
{
|
||||
lambda_invoked =true;
|
||||
}, &h);
|
||||
BEAST_EXPECT(hook_invoked);
|
||||
BEAST_EXPECT(lambda_invoked);
|
||||
}
|
||||
{
|
||||
bool hook_invoked = false;
|
||||
auto h = f(legacy_handler{hook_invoked});
|
||||
using net::asio_handler_allocate;
|
||||
asio_handler_allocate(0, &h);
|
||||
BEAST_EXPECT(hook_invoked);
|
||||
}
|
||||
{
|
||||
bool hook_invoked = false;
|
||||
auto h = f(legacy_handler{hook_invoked});
|
||||
using net::asio_handler_deallocate;
|
||||
asio_handler_deallocate(nullptr, 0, &h);
|
||||
BEAST_EXPECT(hook_invoked);
|
||||
}
|
||||
{
|
||||
bool hook_invoked = false;
|
||||
auto h = f(legacy_handler{hook_invoked});
|
||||
@@ -168,35 +139,6 @@ struct legacy_handler
|
||||
}
|
||||
};
|
||||
|
||||
template<class Function>
|
||||
void
|
||||
asio_handler_invoke(
|
||||
Function&& f,
|
||||
legacy_handler* p)
|
||||
{
|
||||
p->hook_invoked = true;
|
||||
f();
|
||||
}
|
||||
|
||||
inline
|
||||
void*
|
||||
asio_handler_allocate(
|
||||
std::size_t,
|
||||
legacy_handler* p)
|
||||
{
|
||||
p->hook_invoked = true;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
asio_handler_deallocate(
|
||||
void*, std::size_t,
|
||||
legacy_handler* p)
|
||||
{
|
||||
p->hook_invoked = true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool
|
||||
asio_handler_is_continuation(
|
||||
|
Reference in New Issue
Block a user