mirror of
https://github.com/boostorg/beast.git
synced 2025-08-03 06:44:39 +02:00
Remove bind_back_handler
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
Version 215:
|
||||
|
||||
* basic_stream uses boost::shared_ptr
|
||||
* Remove bind_back_handler
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@@ -79,7 +79,6 @@ composed operations:
|
||||
be the same as those of the original handler.
|
||||
]]
|
||||
[[
|
||||
[link beast.ref.boost__beast__bind_back_handler `bind_back_handler`]
|
||||
[link beast.ref.boost__beast__bind_front_handler `bind_front_handler`]
|
||||
][
|
||||
This function creates a new handler which, when invoked, calls
|
||||
|
@@ -63,7 +63,6 @@
|
||||
<member><link linkend="beast.ref.boost__beast__allocate_stable">allocate_stable</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__async_connect">async_connect</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__beast_close_socket">beast_close_socket</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__bind_back_handler">bind_back_handler</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__bind_front_handler">bind_front_handler</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__bind_handler">bind_handler</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__buffer_size">buffer_size</link> <emphasis role="green">🞲</emphasis></member>
|
||||
|
@@ -56,7 +56,6 @@ Enlarged scope
|
||||
* Specify exception safety
|
||||
|
||||
* ([issue 1384]) New functions
|
||||
`bind_back_handler`,
|
||||
`bind_front_handler`
|
||||
|
||||
* Better
|
||||
|
@@ -124,59 +124,6 @@ bind_front_handler(
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/** Bind parameters to a completion handler, creating a new handler.
|
||||
|
||||
This function creates a new handler which, when invoked, calls
|
||||
the original handler with the list of bound arguments. Any
|
||||
parameters passed in the invocation will be forwarded in
|
||||
the parameter list before the bound arguments.
|
||||
|
||||
The passed handler and arguments are forwarded into the returned
|
||||
handler, whose associated allocator and associated executor will
|
||||
will be the same as those of the original handler.
|
||||
|
||||
@par Example
|
||||
|
||||
This function posts the invocation of the specified completion
|
||||
handler with bound arguments:
|
||||
|
||||
@code
|
||||
template <class AsyncReadStream, class ReadHandler>
|
||||
void
|
||||
signal_unreachable (AsyncReadStream& stream, ReadHandler&& handler)
|
||||
{
|
||||
net::post(
|
||||
stream.get_executor(),
|
||||
bind_back_handler (std::forward<ReadHandler> (handler),
|
||||
net::error::network_unreachable, 0));
|
||||
}
|
||||
@endcode
|
||||
|
||||
@param handler The handler to wrap.
|
||||
|
||||
@param args A list of arguments to bind to the handler.
|
||||
The arguments are forwarded into the returned object.
|
||||
*/
|
||||
template<class Handler, class... Args>
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
__implementation_defined__
|
||||
#else
|
||||
auto
|
||||
#endif
|
||||
bind_back_handler(
|
||||
Handler&& handler,
|
||||
Args&&... args) ->
|
||||
detail::bind_back_wrapper<
|
||||
typename std::decay<Handler>::type,
|
||||
typename std::decay<Args>::type...>
|
||||
{
|
||||
return detail::bind_back_wrapper<
|
||||
typename std::decay<Handler>::type,
|
||||
typename std::decay<Args>::type...>(
|
||||
std::forward<Handler>(handler),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
|
@@ -286,252 +286,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// specialization for the most common case,
|
||||
// to reduce instantiation time and memory.
|
||||
template<class Handler>
|
||||
class bind_front_wrapper<
|
||||
Handler, error_code, std::size_t>
|
||||
{
|
||||
Handler h_;
|
||||
error_code ec_;
|
||||
std::size_t n_;
|
||||
|
||||
template<class T, class Executor>
|
||||
friend struct net::associated_executor;
|
||||
|
||||
template<class T, class Allocator>
|
||||
friend struct net::associated_allocator;
|
||||
|
||||
public:
|
||||
using result_type = void; // asio needs this
|
||||
|
||||
bind_front_wrapper(bind_front_wrapper&&) = default;
|
||||
bind_front_wrapper(bind_front_wrapper const&) = default;
|
||||
|
||||
template<class DeducedHandler>
|
||||
bind_front_wrapper(DeducedHandler&& handler,
|
||||
error_code ec, std::size_t n)
|
||||
: h_(std::forward<DeducedHandler>(handler))
|
||||
, ec_(ec)
|
||||
, n_(n)
|
||||
{
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
void operator()(Ts&&... ts)
|
||||
{
|
||||
h_(ec_, n_, std::forward<Ts>(ts)...);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<class Function>
|
||||
friend
|
||||
void asio_handler_invoke(
|
||||
Function&& f, bind_front_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_invoke;
|
||||
asio_handler_invoke(f, std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
bool asio_handler_is_continuation(
|
||||
bind_front_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_is_continuation;
|
||||
return asio_handler_is_continuation(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
void* asio_handler_allocate(
|
||||
std::size_t size, bind_front_wrapper* 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, bind_front_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_deallocate;
|
||||
asio_handler_deallocate(
|
||||
p, size, std::addressof(op->h_));
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// bind_back
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<class Handler, class... Args>
|
||||
class bind_back_wrapper
|
||||
{
|
||||
Handler h_;
|
||||
detail::tuple<Args...> args_;
|
||||
|
||||
template<class T, class Executor>
|
||||
friend struct net::associated_executor;
|
||||
|
||||
template<class T, class Allocator>
|
||||
friend struct net::associated_allocator;
|
||||
|
||||
template<std::size_t... I, class... Ts>
|
||||
void
|
||||
invoke(
|
||||
mp11::index_sequence<I...>,
|
||||
Ts&&... ts)
|
||||
{
|
||||
h_( std::forward<Ts>(ts)...,
|
||||
detail::get<I>(std::move(args_))...);
|
||||
}
|
||||
|
||||
public:
|
||||
using result_type = void; // asio needs this
|
||||
|
||||
bind_back_wrapper(bind_back_wrapper&&) = default;
|
||||
bind_back_wrapper(bind_back_wrapper const&) = default;
|
||||
|
||||
template<class Handler_, class... Args_>
|
||||
bind_back_wrapper(Handler_&& handler, Args_&&... args)
|
||||
: h_(std::forward<Handler_>(handler))
|
||||
, args_(std::forward<Args_>(args)...)
|
||||
{
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
void operator()(Ts&&... ts)
|
||||
{
|
||||
invoke(
|
||||
mp11::index_sequence_for<Args...>{},
|
||||
std::forward<Ts>(ts)...);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<class Function>
|
||||
friend
|
||||
void asio_handler_invoke(
|
||||
Function&& f, bind_back_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_invoke;
|
||||
asio_handler_invoke(f, std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
bool asio_handler_is_continuation(
|
||||
bind_back_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_is_continuation;
|
||||
return asio_handler_is_continuation(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
void* asio_handler_allocate(
|
||||
std::size_t size, bind_back_wrapper* 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, bind_back_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_deallocate;
|
||||
asio_handler_deallocate(
|
||||
p, size, std::addressof(op->h_));
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// specialization for the most common case,
|
||||
// to reduce instantiation time and memory.
|
||||
template<class Handler>
|
||||
class bind_back_wrapper<
|
||||
Handler, error_code, std::size_t>
|
||||
{
|
||||
Handler h_;
|
||||
error_code ec_;
|
||||
std::size_t n_;
|
||||
|
||||
template<class T, class Executor>
|
||||
friend struct net::associated_executor;
|
||||
|
||||
template<class T, class Allocator>
|
||||
friend struct net::associated_allocator;
|
||||
|
||||
public:
|
||||
using result_type = void; // asio needs this
|
||||
|
||||
bind_back_wrapper(bind_back_wrapper&&) = default;
|
||||
bind_back_wrapper(bind_back_wrapper const&) = default;
|
||||
|
||||
template<class DeducedHandler>
|
||||
bind_back_wrapper(DeducedHandler&& handler,
|
||||
error_code ec, std::size_t n)
|
||||
: h_(std::forward<DeducedHandler>(handler))
|
||||
, ec_(ec)
|
||||
, n_(n)
|
||||
{
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
void operator()(Ts&&... ts)
|
||||
{
|
||||
h_(std::forward<Ts>(ts)..., ec_, n_);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<class Function>
|
||||
friend
|
||||
void asio_handler_invoke(
|
||||
Function&& f, bind_back_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_invoke;
|
||||
asio_handler_invoke(f, std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
bool asio_handler_is_continuation(
|
||||
bind_back_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_is_continuation;
|
||||
return asio_handler_is_continuation(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
|
||||
friend
|
||||
void* asio_handler_allocate(
|
||||
std::size_t size, bind_back_wrapper* 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, bind_back_wrapper* op)
|
||||
{
|
||||
using net::asio_handler_deallocate;
|
||||
asio_handler_deallocate(
|
||||
p, size, std::addressof(op->h_));
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
} // detail
|
||||
} // beast
|
||||
} // boost
|
||||
@@ -575,23 +329,6 @@ struct associated_executor<
|
||||
}
|
||||
};
|
||||
|
||||
template<class Handler, class... Args, class Executor>
|
||||
struct associated_executor<
|
||||
beast::detail::bind_back_wrapper<Handler, Args...>, Executor>
|
||||
{
|
||||
using type = typename
|
||||
associated_executor<Handler, Executor>::type;
|
||||
|
||||
static
|
||||
type
|
||||
get(beast::detail::bind_back_wrapper<Handler, Args...> const& op,
|
||||
Executor const& ex = Executor{}) noexcept
|
||||
{
|
||||
return associated_executor<
|
||||
Handler, Executor>::get(op.h_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
template<class Handler, class... Args, class Allocator>
|
||||
@@ -628,23 +365,6 @@ struct associated_allocator<
|
||||
}
|
||||
};
|
||||
|
||||
template<class Handler, class... Args, class Allocator>
|
||||
struct associated_allocator<
|
||||
beast::detail::bind_back_wrapper<Handler, Args...>, Allocator>
|
||||
{
|
||||
using type = typename
|
||||
associated_allocator<Handler, Allocator>::type;
|
||||
|
||||
static
|
||||
type
|
||||
get(beast::detail::bind_back_wrapper<Handler, Args...> const& op,
|
||||
Allocator const& alloc = Allocator{}) noexcept
|
||||
{
|
||||
return associated_allocator<
|
||||
Handler, Allocator>::get(op.h_, alloc);
|
||||
}
|
||||
};
|
||||
|
||||
} // asio
|
||||
} // boost
|
||||
|
||||
@@ -669,11 +389,6 @@ void
|
||||
bind(boost::beast::detail::bind_front_wrapper<
|
||||
Handler, Args...>, ...) = delete;
|
||||
|
||||
template<class Handler, class... Args>
|
||||
void
|
||||
bind(boost::beast::detail::bind_back_wrapper<
|
||||
Handler, Args...>, ...) = delete;
|
||||
|
||||
} // std
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@@ -240,12 +240,6 @@ public:
|
||||
{
|
||||
std::bind(bind_front_handler(test_cb{}));
|
||||
}
|
||||
|
||||
void
|
||||
failStdBindBack()
|
||||
{
|
||||
std::bind(bind_back_handler(test_cb{}));
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -475,92 +469,6 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
testBindBackHandler()
|
||||
{
|
||||
using m1 = move_arg<1>;
|
||||
using m2 = move_arg<2>;
|
||||
|
||||
// 0-ary
|
||||
bind_back_handler(test_cb{})();
|
||||
|
||||
// 1-ary
|
||||
bind_back_handler(test_cb{}, 42)();
|
||||
bind_back_handler(test_cb{})(42);
|
||||
|
||||
// 2-ary
|
||||
bind_back_handler(test_cb{}, 42, "s")();
|
||||
bind_back_handler(test_cb{}, "s")(42);
|
||||
bind_back_handler(test_cb{})(42, "s");
|
||||
|
||||
// 3-ary
|
||||
bind_back_handler(test_cb{}, 42, "s", m1{})();
|
||||
bind_back_handler(test_cb{}, m1{})(42, "s");
|
||||
bind_back_handler(test_cb{}, "s", m1{})(42);
|
||||
bind_back_handler(test_cb{})(42, "s", m1{});
|
||||
|
||||
// 4-ary
|
||||
bind_back_handler(test_cb{}, 42, "s", m1{}, m2{})();
|
||||
bind_back_handler(test_cb{}, "s", m1{}, m2{})(42);
|
||||
bind_back_handler(test_cb{}, m1{}, m2{})(42, "s");
|
||||
bind_back_handler(test_cb{}, "s", m1{}, m2{})(42);
|
||||
bind_back_handler(test_cb{})(42, "s", m1{}, m2{});
|
||||
|
||||
error_code ec;
|
||||
std::size_t n = 256;
|
||||
|
||||
// void(error_code, size_t)
|
||||
bind_back_handler(test_cb{}, ec, n)();
|
||||
|
||||
// void(error_code, size_t)(string_view)
|
||||
bind_back_handler(test_cb{}, "s")(ec, n);
|
||||
|
||||
// perfect forwarding
|
||||
{
|
||||
std::shared_ptr<int> const sp =
|
||||
std::make_shared<int>(42);
|
||||
bind_back_handler(test_cb{}, sp)();
|
||||
BEAST_EXPECT(sp.get() != nullptr);
|
||||
}
|
||||
|
||||
// associated executor
|
||||
{
|
||||
net::io_context ioc;
|
||||
|
||||
testHooks(ioc, bind_back_handler(net::bind_executor(
|
||||
test_executor(*this, ioc), test_cb{})
|
||||
));
|
||||
testHooks(ioc, bind_back_handler(net::bind_executor(
|
||||
test_executor(*this, ioc), test_cb{}),
|
||||
42));
|
||||
testHooks(ioc, bind_back_handler(net::bind_executor(
|
||||
test_executor(*this, ioc), test_cb{}),
|
||||
42, "s"));
|
||||
testHooks(ioc, bind_back_handler(net::bind_executor(
|
||||
test_executor(*this, ioc), test_cb{}),
|
||||
42, "s", m1{}));
|
||||
testHooks(ioc, bind_back_handler(net::bind_executor(
|
||||
test_executor(*this, ioc), test_cb{}),
|
||||
42, "s", m1{}, m2{}));
|
||||
testHooks(ioc, bind_back_handler(net::bind_executor(
|
||||
test_executor(*this, ioc), test_cb{}),
|
||||
ec, n));
|
||||
}
|
||||
|
||||
// legacy hooks
|
||||
legacy_handler::test(
|
||||
[](legacy_handler h)
|
||||
{
|
||||
return bind_back_handler(h);
|
||||
});
|
||||
legacy_handler::test(
|
||||
[](legacy_handler h)
|
||||
{
|
||||
return bind_back_handler(
|
||||
h, error_code{}, std::size_t{});
|
||||
});
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
template <class AsyncReadStream, class ReadHandler>
|
||||
@@ -583,16 +491,6 @@ public:
|
||||
net::error::eof, 0));
|
||||
}
|
||||
|
||||
template <class AsyncReadStream, class ReadHandler>
|
||||
void
|
||||
signal_unreachable (AsyncReadStream& stream, ReadHandler&& handler)
|
||||
{
|
||||
net::post(
|
||||
stream.get_executor(),
|
||||
bind_back_handler (std::forward<ReadHandler> (handler),
|
||||
net::error::network_unreachable, 0));
|
||||
}
|
||||
|
||||
void
|
||||
testJavadocs()
|
||||
{
|
||||
@@ -603,10 +501,6 @@ public:
|
||||
BEAST_EXPECT((
|
||||
&bind_handler_test::signal_eof<
|
||||
test::stream, handler<error_code, std::size_t>>));
|
||||
|
||||
BEAST_EXPECT((
|
||||
&bind_handler_test::signal_unreachable<
|
||||
test::stream, handler<error_code, std::size_t>>));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -616,7 +510,6 @@ public:
|
||||
{
|
||||
testBindHandler();
|
||||
testBindFrontHandler();
|
||||
testBindBackHandler();
|
||||
testJavadocs();
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user