2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
8 #ifndef BEAST_HANDLER_HELPERS_HPP
9 #define BEAST_HANDLER_HELPERS_HPP
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>
19 * asio_handler_allocate
20 * asio_handler_deallocate
22 * asio_handler_is_continuation
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.
29 namespace beast_asio_helpers {
31 /// Allocation function for handlers.
32 template <class Handler>
35 allocate(std::size_t s, Handler& handler)
37 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
38 return ::operator new(s);
40 using boost::asio::asio_handler_allocate;
41 return asio_handler_allocate(s, std::addressof(handler));
45 /// Deallocation function for handlers.
46 template<class Handler>
49 deallocate(void* p, std::size_t s, Handler& handler)
51 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
54 using boost::asio::asio_handler_deallocate;
55 asio_handler_deallocate(p, s, std::addressof(handler));
59 /// Invoke function for handlers.
60 template<class Function, class Handler>
63 invoke(Function& function, Handler& handler)
65 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
66 Function tmp(function);
69 using boost::asio::asio_handler_invoke;
70 asio_handler_invoke(function, std::addressof(handler));
74 /// Invoke function for handlers.
75 template<class Function, class Handler>
78 invoke(Function const& function, Handler& handler)
80 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
81 Function tmp(function);
84 using boost::asio::asio_handler_invoke;
85 asio_handler_invoke(function, std::addressof(handler));
89 /// Returns true if handler represents a continuation of the asynchronous operation
90 template<class Handler>
93 is_continuation(Handler& handler)
95 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
98 using boost::asio::asio_handler_is_continuation;
99 return asio_handler_is_continuation(std::addressof(handler));
103 } // beast_asio_helpers