Files
boost_beast/include/beast/core/bind_handler.hpp
T

71 lines
2.1 KiB
C++
Raw Normal View History

2017-07-20 08:01:46 -07:00
//
2017-02-06 20:07:03 -05:00
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2017-07-20 08:01:46 -07:00
//
// 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)
//
#ifndef BEAST_BIND_HANDLER_HPP
#define BEAST_BIND_HANDLER_HPP
2016-05-07 14:57:15 -04:00
#include <beast/core/handler_concepts.hpp>
#include <beast/core/detail/bind_handler.hpp>
2017-07-20 08:01:46 -07:00
#include <type_traits>
#include <utility>
namespace beast {
2017-02-06 10:56:37 -05:00
/** Bind parameters to a completion handler, creating a new handler.
2017-07-20 08:01:46 -07:00
This function creates a new handler which, when invoked with no
2017-02-06 10:56:37 -05:00
parameters, calls the original handler with the list of bound
arguments. The passed handler and arguments are forwarded into
the returned handler, which provides the same `io_service`
execution guarantees as the original handler.
2017-07-20 08:01:46 -07:00
2017-02-06 10:56:37 -05:00
Unlike `io_service::wrap`, the returned handler can be used in
a subsequent call to `io_service::post` instead of
`io_service::dispatch`, to ensure that the handler will not be
invoked immediately by the calling function.
2017-07-20 08:01:46 -07:00
Example:
2017-02-06 10:56:37 -05:00
2017-07-20 08:01:46 -07:00
@code
2017-02-06 10:56:37 -05:00
2017-07-20 08:01:46 -07:00
template<class AsyncReadStream, class ReadHandler>
void
do_cancel(AsyncReadStream& stream, ReadHandler&& handler)
{
stream.get_io_service().post(
bind_handler(std::forward<ReadHandler>(handler),
boost::asio::error::operation_aborted, 0));
}
2017-02-06 10:56:37 -05:00
2017-07-20 08:01:46 -07:00
@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.
*/
2017-02-06 10:56:37 -05:00
template<class Handler, class... Args>
2017-07-20 08:01:46 -07:00
#if GENERATING_DOCS
implementation_defined
#else
detail::bound_handler<
2017-02-06 10:56:37 -05:00
typename std::decay<Handler>::type, Args...>
2017-07-20 08:01:46 -07:00
#endif
2017-02-06 10:56:37 -05:00
bind_handler(Handler&& handler, Args&&... args)
2017-07-20 08:01:46 -07:00
{
static_assert(is_CompletionHandler<
2017-02-06 10:56:37 -05:00
Handler, void(Args...)>::value,
"Handler requirements not met");
2017-07-20 08:01:46 -07:00
return detail::bound_handler<typename std::decay<
2017-02-06 10:56:37 -05:00
Handler>::type, Args...>(std::forward<
Handler>(handler), std::forward<Args>(args)...);
2017-07-20 08:01:46 -07:00
}
} // beast
#endif