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

72 lines
2.1 KiB
C++
Raw Normal View History

2016-04-19 20:29:16 -04:00
//
2017-02-06 20:07:03 -05:00
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2016-04-19 20:29:16 -04: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)
//
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
#include <beast/config.hpp>
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 {
2017-02-06 10:56:37 -05:00
/** Bind parameters to a completion handler, creating a new handler.
2016-04-01 11:46:32 -04: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.
2016-04-01 11:46:32 -04: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.
2016-04-01 11:46:32 -04:00
Example:
2017-02-06 10:56:37 -05:00
2016-04-01 11:46:32 -04:00
@code
2017-02-06 10:56:37 -05:00
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));
}
2017-02-06 10:56:37 -05:00
2016-04-01 11:46:32 -04:00
@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
*/
2017-02-06 10:56:37 -05:00
template<class Handler, class... Args>
2016-04-01 11:46:32 -04:00
#if GENERATING_DOCS
implementation_defined
#else
2016-04-22 07:34:44 -04:00
detail::bound_handler<
2017-02-06 10:56:37 -05:00
typename std::decay<Handler>::type, Args...>
2016-04-01 11:46:32 -04:00
#endif
2017-02-06 10:56:37 -05:00
bind_handler(Handler&& handler, Args&&... args)
2014-03-07 20:06:12 -08:00
{
static_assert(is_CompletionHandler<
2017-02-06 10:56:37 -05:00
Handler, void(Args...)>::value,
"Handler requirements not met");
2016-04-22 07:34:44 -04: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)...);
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