10ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
20ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// detail/wrapped_handler.hpp
30ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// ~~~~~~~~~~~~~~~~~~~~~~~~~~
40ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
50ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
60ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
70ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Distributed under the Boost Software License, Version 1.0. (See accompanying
80ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
90ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#ifndef ASIO_DETAIL_WRAPPED_HANDLER_HPP
120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#define ASIO_DETAIL_WRAPPED_HANDLER_HPP
130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/bind_handler.hpp"
160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/handler_alloc_helpers.hpp"
170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/handler_cont_helpers.hpp"
180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/handler_invoke_helpers.hpp"
190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/push_options.hpp"
210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace asio {
230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace detail {
240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiestruct is_continuation_delegated
260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Dispatcher, typename Handler>
280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  bool operator()(Dispatcher&, Handler& handler) const
290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return asio_handler_cont_helpers::is_continuation(handler);
310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiestruct is_continuation_if_running
350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Dispatcher, typename Handler>
370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  bool operator()(Dispatcher& dispatcher, Handler&) const
380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return dispatcher.running_in_this_thread();
400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Dispatcher, typename Handler,
440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    typename IsContinuation = is_continuation_delegated>
450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass wrapped_handler
460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiepublic:
480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  typedef void result_type;
490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  wrapped_handler(Dispatcher dispatcher, Handler& handler)
510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : dispatcher_(dispatcher),
520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      handler_(ASIO_MOVE_CAST(Handler)(handler))
530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  wrapped_handler(const wrapped_handler& other)
570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : dispatcher_(other.dispatcher_),
580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      handler_(other.handler_)
590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  wrapped_handler(wrapped_handler&& other)
630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : dispatcher_(other.dispatcher_),
640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()()
690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(ASIO_MOVE_CAST(Handler)(handler_));
710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()() const
740ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
750ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(handler_);
760ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
770ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
780ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1>
790ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1)
800ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
810ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
820ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
830ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
840ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1>
850ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1) const
860ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
870ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
880ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
890ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
900ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2>
910ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2)
920ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
930ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
940ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
950ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
960ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2>
970ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2) const
980ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
990ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
1000ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1010ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1020ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2, typename Arg3>
1030ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
1040ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1050ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
1060ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1070ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1080ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2, typename Arg3>
1090ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
1100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
1120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
1150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
1160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      const Arg4& arg4)
1170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(
1190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie        detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
1200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
1230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
1240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      const Arg4& arg4) const
1250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(
1270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie        detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
1280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
1310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      typename Arg5>
1320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
1330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      const Arg4& arg4, const Arg5& arg5)
1340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(
1360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie        detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
1370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
1400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      typename Arg5>
1410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
1420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      const Arg4& arg4, const Arg5& arg5) const
1430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    dispatcher_.dispatch(
1450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie        detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
1460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//private:
1490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  Dispatcher dispatcher_;
1500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  Handler handler_;
1510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
1520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Handler, typename Context>
1540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass rewrapped_handler
1550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
1560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiepublic:
1570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  explicit rewrapped_handler(Handler& handler, const Context& context)
1580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : context_(context),
1590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      handler_(ASIO_MOVE_CAST(Handler)(handler))
1600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  explicit rewrapped_handler(const Handler& handler, const Context& context)
1640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : context_(context),
1650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      handler_(handler)
1660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  rewrapped_handler(const rewrapped_handler& other)
1700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : context_(other.context_),
1710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      handler_(other.handler_)
1720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1740ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1750ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  rewrapped_handler(rewrapped_handler&& other)
1760ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : context_(ASIO_MOVE_CAST(Context)(other.context_)),
1770ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      handler_(ASIO_MOVE_CAST(Handler)(other.handler_))
1780ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1790ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1800ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1810ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()()
1820ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1830ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    handler_();
1840ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1850ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1860ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void operator()() const
1870ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1880ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    handler_();
1890ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1900ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1910ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//private:
1920ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  Context context_;
1930ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  Handler handler_;
1940ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
1950ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1960ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Dispatcher, typename Handler, typename IsContinuation>
1970ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void* asio_handler_allocate(std::size_t size,
1980ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
1990ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2000ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  return asio_handler_alloc_helpers::allocate(
2010ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      size, this_handler->handler_);
2020ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2030ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2040ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Dispatcher, typename Handler, typename IsContinuation>
2050ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void asio_handler_deallocate(void* pointer, std::size_t size,
2060ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
2070ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2080ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  asio_handler_alloc_helpers::deallocate(
2090ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      pointer, size, this_handler->handler_);
2100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Dispatcher, typename Handler, typename IsContinuation>
2130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline bool asio_handler_is_continuation(
2140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
2150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  return IsContinuation()(this_handler->dispatcher_, this_handler->handler_);
2170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Function, typename Dispatcher,
2200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    typename Handler, typename IsContinuation>
2210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void asio_handler_invoke(Function& function,
2220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
2230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  this_handler->dispatcher_.dispatch(
2250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      rewrapped_handler<Function, Handler>(
2260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie        function, this_handler->handler_));
2270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Function, typename Dispatcher,
2300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    typename Handler, typename IsContinuation>
2310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void asio_handler_invoke(const Function& function,
2320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
2330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  this_handler->dispatcher_.dispatch(
2350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      rewrapped_handler<Function, Handler>(
2360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie        function, this_handler->handler_));
2370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Handler, typename Context>
2400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void* asio_handler_allocate(std::size_t size,
2410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    rewrapped_handler<Handler, Context>* this_handler)
2420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  return asio_handler_alloc_helpers::allocate(
2440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      size, this_handler->context_);
2450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Handler, typename Context>
2480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void asio_handler_deallocate(void* pointer, std::size_t size,
2490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    rewrapped_handler<Handler, Context>* this_handler)
2500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  asio_handler_alloc_helpers::deallocate(
2520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      pointer, size, this_handler->context_);
2530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Dispatcher, typename Context>
2560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline bool asio_handler_is_continuation(
2570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    rewrapped_handler<Dispatcher, Context>* this_handler)
2580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  return asio_handler_cont_helpers::is_continuation(
2600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      this_handler->context_);
2610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Function, typename Handler, typename Context>
2640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void asio_handler_invoke(Function& function,
2650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    rewrapped_handler<Handler, Context>* this_handler)
2660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  asio_handler_invoke_helpers::invoke(
2680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      function, this_handler->context_);
2690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffietemplate <typename Function, typename Handler, typename Context>
2720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieinline void asio_handler_invoke(const Function& function,
2730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    rewrapped_handler<Handler, Context>* this_handler)
2740ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
2750ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  asio_handler_invoke_helpers::invoke(
2760ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie      function, this_handler->context_);
2770ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}
2780ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2790ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace detail
2800ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace asio
2810ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2820ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/pop_options.hpp"
2830ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
2840ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#endif // ASIO_DETAIL_WRAPPED_HANDLER_HPP
285