]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/core/handler_helpers.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / core / handler_helpers.hpp
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_HANDLER_HELPERS_HPP
9 #define BEAST_HANDLER_HELPERS_HPP
10
11 #include <beast/config.hpp>
12 #include <boost/asio/handler_alloc_hook.hpp>
13 #include <boost/asio/handler_continuation_hook.hpp>
14 #include <boost/asio/handler_invoke_hook.hpp>
15 #include <memory>
16
17 /* Calls to:
18
19 * asio_handler_allocate
20 * asio_handler_deallocate
21 * asio_handler_invoke
22 * asio_handler_is_continuation
23
24 must be made from a namespace that does not
25 contain overloads of this function. The beast_asio_helpers
26 namespace is defined here for that purpose.
27 */
28
29 namespace beast_asio_helpers {
30
31 /// Allocation function for handlers.
32 template <class Handler>
33 inline
34 void*
35 allocate(std::size_t s, Handler& handler)
36 {
37 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
38 return ::operator new(s);
39 #else
40 using boost::asio::asio_handler_allocate;
41 return asio_handler_allocate(s, std::addressof(handler));
42 #endif
43 }
44
45 /// Deallocation function for handlers.
46 template<class Handler>
47 inline
48 void
49 deallocate(void* p, std::size_t s, Handler& handler)
50 {
51 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
52 ::operator delete(p);
53 #else
54 using boost::asio::asio_handler_deallocate;
55 asio_handler_deallocate(p, s, std::addressof(handler));
56 #endif
57 }
58
59 /// Invoke function for handlers.
60 template<class Function, class Handler>
61 inline
62 void
63 invoke(Function& function, Handler& handler)
64 {
65 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
66 Function tmp(function);
67 tmp();
68 #else
69 using boost::asio::asio_handler_invoke;
70 asio_handler_invoke(function, std::addressof(handler));
71 #endif
72 }
73
74 /// Invoke function for handlers.
75 template<class Function, class Handler>
76 inline
77 void
78 invoke(Function const& function, Handler& handler)
79 {
80 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
81 Function tmp(function);
82 tmp();
83 #else
84 using boost::asio::asio_handler_invoke;
85 asio_handler_invoke(function, std::addressof(handler));
86 #endif
87 }
88
89 /// Returns true if handler represents a continuation of the asynchronous operation
90 template<class Handler>
91 inline
92 bool
93 is_continuation(Handler& handler)
94 {
95 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
96 return false;
97 #else
98 using boost::asio::asio_handler_is_continuation;
99 return asio_handler_is_continuation(std::addressof(handler));
100 #endif
101 }
102
103 } // beast_asio_helpers
104
105 #endif