summaryrefslogtreecommitdiff
path: root/boost/asio/detail/wrapped_handler.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/asio/detail/wrapped_handler.hpp')
-rw-r--r--boost/asio/detail/wrapped_handler.hpp59
1 files changed, 48 insertions, 11 deletions
diff --git a/boost/asio/detail/wrapped_handler.hpp b/boost/asio/detail/wrapped_handler.hpp
index d82da22b70..0ff28eddb1 100644
--- a/boost/asio/detail/wrapped_handler.hpp
+++ b/boost/asio/detail/wrapped_handler.hpp
@@ -2,7 +2,7 @@
// detail/wrapped_handler.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// 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)
@@ -17,6 +17,7 @@
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
+#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -25,7 +26,26 @@ namespace boost {
namespace asio {
namespace detail {
-template <typename Dispatcher, typename Handler>
+struct is_continuation_delegated
+{
+ template <typename Dispatcher, typename Handler>
+ bool operator()(Dispatcher&, Handler& handler) const
+ {
+ return boost_asio_handler_cont_helpers::is_continuation(handler);
+ }
+};
+
+struct is_continuation_if_running
+{
+ template <typename Dispatcher, typename Handler>
+ bool operator()(Dispatcher& dispatcher, Handler&) const
+ {
+ return dispatcher.running_in_this_thread();
+ }
+};
+
+template <typename Dispatcher, typename Handler,
+ typename IsContinuation = is_continuation_delegated>
class wrapped_handler
{
public:
@@ -53,7 +73,7 @@ public:
void operator()()
{
- dispatcher_.dispatch(handler_);
+ dispatcher_.dispatch(BOOST_ASIO_MOVE_CAST(Handler)(handler_));
}
void operator()() const
@@ -181,34 +201,43 @@ public:
Handler handler_;
};
-template <typename Dispatcher, typename Handler>
+template <typename Dispatcher, typename Handler, typename IsContinuation>
inline void* asio_handler_allocate(std::size_t size,
- wrapped_handler<Dispatcher, Handler>* this_handler)
+ wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
{
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
}
-template <typename Dispatcher, typename Handler>
+template <typename Dispatcher, typename Handler, typename IsContinuation>
inline void asio_handler_deallocate(void* pointer, std::size_t size,
- wrapped_handler<Dispatcher, Handler>* this_handler)
+ wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
}
-template <typename Function, typename Dispatcher, typename Handler>
+template <typename Dispatcher, typename Handler, typename IsContinuation>
+inline bool asio_handler_is_continuation(
+ wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
+{
+ return IsContinuation()(this_handler->dispatcher_, this_handler->handler_);
+}
+
+template <typename Function, typename Dispatcher,
+ typename Handler, typename IsContinuation>
inline void asio_handler_invoke(Function& function,
- wrapped_handler<Dispatcher, Handler>* this_handler)
+ wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
{
this_handler->dispatcher_.dispatch(
rewrapped_handler<Function, Handler>(
function, this_handler->handler_));
}
-template <typename Function, typename Dispatcher, typename Handler>
+template <typename Function, typename Dispatcher,
+ typename Handler, typename IsContinuation>
inline void asio_handler_invoke(const Function& function,
- wrapped_handler<Dispatcher, Handler>* this_handler)
+ wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
{
this_handler->dispatcher_.dispatch(
rewrapped_handler<Function, Handler>(
@@ -231,6 +260,14 @@ inline void asio_handler_deallocate(void* pointer, std::size_t size,
pointer, size, this_handler->context_);
}
+template <typename Dispatcher, typename Context>
+inline bool asio_handler_is_continuation(
+ rewrapped_handler<Dispatcher, Context>* this_handler)
+{
+ return boost_asio_handler_cont_helpers::is_continuation(
+ this_handler->context_);
+}
+
template <typename Function, typename Handler, typename Context>
inline void asio_handler_invoke(Function& function,
rewrapped_handler<Handler, Context>* this_handler)