]> git.proxmox.com Git - ceph.git/blame - ceph/src/Beast/include/beast/core/bind_handler.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / core / bind_handler.hpp
CommitLineData
7c673cae
FG
1//
2// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7
8#ifndef BEAST_BIND_HANDLER_HPP
9#define BEAST_BIND_HANDLER_HPP
10
11#include <beast/config.hpp>
12#include <beast/core/handler_concepts.hpp>
13#include <beast/core/detail/bind_handler.hpp>
14#include <type_traits>
15#include <utility>
16
17namespace beast {
18
19/** Bind parameters to a completion handler, creating a new handler.
20
21 This function creates a new handler which, when invoked with no
22 parameters, calls the original handler with the list of bound
23 arguments. The passed handler and arguments are forwarded into
24 the returned handler, which provides the same `io_service`
25 execution guarantees as the original handler.
26
27 Unlike `io_service::wrap`, the returned handler can be used in
28 a subsequent call to `io_service::post` instead of
29 `io_service::dispatch`, to ensure that the handler will not be
30 invoked immediately by the calling function.
31
32 Example:
33
34 @code
35
36 template<class AsyncReadStream, class ReadHandler>
37 void
38 do_cancel(AsyncReadStream& stream, ReadHandler&& handler)
39 {
40 stream.get_io_service().post(
41 bind_handler(std::forward<ReadHandler>(handler),
42 boost::asio::error::operation_aborted, 0));
43 }
44
45 @endcode
46
47 @param handler The handler to wrap.
48
49 @param args A list of arguments to bind to the handler. The
50 arguments are forwarded into the returned object.
51*/
52template<class Handler, class... Args>
53#if BEAST_DOXYGEN
54implementation_defined
55#else
56detail::bound_handler<
57 typename std::decay<Handler>::type, Args...>
58#endif
59bind_handler(Handler&& handler, Args&&... args)
60{
61 static_assert(is_CompletionHandler<
62 Handler, void(Args...)>::value,
63 "Handler requirements not met");
64 return detail::bound_handler<typename std::decay<
65 Handler>::type, Args...>(std::forward<
66 Handler>(handler), std::forward<Args>(args)...);
67}
68
69} // beast
70
71#endif