Chris@16: // Chris@16: // handler_invoke_hook.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_HANDLER_INVOKE_HOOK_HPP Chris@16: #define BOOST_ASIO_HANDLER_INVOKE_HOOK_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: Chris@16: /** @defgroup asio_handler_invoke boost::asio::asio_handler_invoke Chris@16: * Chris@16: * @brief Default invoke function for handlers. Chris@16: * Chris@16: * Completion handlers for asynchronous operations are invoked by the Chris@16: * io_service associated with the corresponding object (e.g. a socket or Chris@16: * deadline_timer). Certain guarantees are made on when the handler may be Chris@16: * invoked, in particular that a handler can only be invoked from a thread that Chris@16: * is currently calling @c run() on the corresponding io_service object. Chris@16: * Handlers may subsequently be invoked through other objects (such as Chris@16: * io_service::strand objects) that provide additional guarantees. Chris@16: * Chris@16: * When asynchronous operations are composed from other asynchronous Chris@16: * operations, all intermediate handlers should be invoked using the same Chris@16: * method as the final handler. This is required to ensure that user-defined Chris@16: * objects are not accessed in a way that may violate the guarantees. This Chris@16: * hooking function ensures that the invoked method used for the final handler Chris@16: * is accessible at each intermediate step. Chris@16: * Chris@16: * Implement asio_handler_invoke for your own handlers to specify a custom Chris@16: * invocation strategy. Chris@16: * Chris@16: * This default implementation invokes the function object like so: Chris@16: * @code function(); @endcode Chris@16: * If necessary, the default implementation makes a copy of the function object Chris@16: * so that the non-const operator() can be used. Chris@16: * Chris@16: * @par Example Chris@16: * @code Chris@16: * class my_handler; Chris@16: * Chris@16: * template Chris@16: * void asio_handler_invoke(Function function, my_handler* context) Chris@16: * { Chris@16: * context->strand_.dispatch(function); Chris@16: * } Chris@16: * @endcode Chris@16: */ Chris@16: /*@{*/ Chris@16: Chris@16: /// Default handler invocation hook used for non-const function objects. Chris@16: template Chris@16: inline void asio_handler_invoke(Function& function, ...) Chris@16: { Chris@16: function(); Chris@16: } Chris@16: Chris@16: /// Default handler invocation hook used for const function objects. Chris@16: template Chris@16: inline void asio_handler_invoke(const Function& function, ...) Chris@16: { Chris@16: Function tmp(function); Chris@16: tmp(); Chris@16: } Chris@16: Chris@16: /*@}*/ Chris@16: Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_HANDLER_INVOKE_HOOK_HPP