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

69 lines
2.1 KiB
C++
Raw Normal View History

2016-04-19 20:29:16 -04:00
//
// Copyright (c) 2013-2016 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)
//
2014-03-07 20:06:12 -08:00
2016-04-19 20:29:16 -04:00
#ifndef BEAST_BIND_HANDLER_HPP
#define BEAST_BIND_HANDLER_HPP
2014-03-07 20:06:12 -08:00
2016-05-07 14:57:15 -04:00
#include <beast/core/handler_concepts.hpp>
#include <beast/core/detail/bind_handler.hpp>
2015-10-07 20:46:52 -07:00
#include <type_traits>
#include <utility>
2014-03-07 20:06:12 -08:00
namespace beast {
2016-04-01 11:46:32 -04:00
/** Bind parameters to a completion handler, creating a wrapped handler.
This function creates a new handler which, when invoked with no
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
2016-04-01 11:46:32 -04:00
handler.
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.
Example:
@code
2016-04-22 19:02:07 -04:00
template<class AsyncReadStream, class ReadHandler>
2016-04-01 11:46:32 -04:00
void
do_cancel(AsyncReadStream& stream, ReadHandler&& handler)
{
stream.get_io_service().post(
bind_handler(std::forward<ReadHandler>(handler),
boost::asio::error::operation_aborted, 0));
}
@endcode
@param handler The handler to wrap.
@param args A list of arguments to bind to the handler. The
2016-04-22 07:34:44 -04:00
arguments are forwarded into the returned object.
2014-03-07 20:06:12 -08:00
*/
2016-04-01 11:46:32 -04:00
template<class CompletionHandler, class... Args>
#if GENERATING_DOCS
implementation_defined
#else
2016-04-22 07:34:44 -04:00
detail::bound_handler<
typename std::decay<CompletionHandler>::type, Args...>
2016-04-01 11:46:32 -04:00
#endif
bind_handler(CompletionHandler&& handler, Args&&... args)
2014-03-07 20:06:12 -08:00
{
static_assert(is_CompletionHandler<
CompletionHandler, void(Args...)>::value,
"CompletionHandler requirements not met");
2016-04-22 07:34:44 -04:00
return detail::bound_handler<typename std::decay<
CompletionHandler>::type, Args...>(std::forward<
2016-04-01 11:46:32 -04:00
CompletionHandler>(handler),
std::forward<Args>(args)...);
2014-03-07 20:06:12 -08:00
}
2016-04-01 11:46:32 -04:00
} // beast
2014-03-07 20:06:12 -08:00
#endif