handler_invoke_hook.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // handler_invoke_hook.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_HANDLER_INVOKE_HOOK_HPP
  11. #define BOOST_ASIO_HANDLER_INVOKE_HOOK_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/push_options.hpp>
  16. namespace boost {
  17. namespace asio {
  18. /// Default invoke function for handlers.
  19. /**
  20. * Completion handlers for asynchronous operations are invoked by the
  21. * io_service associated with the corresponding object (e.g. a socket or
  22. * deadline_timer). Certain guarantees are made on when the handler may be
  23. * invoked, in particular that a handler can only be invoked from a thread that
  24. * is currently calling @c run() on the corresponding io_service object.
  25. * Handlers may subsequently be invoked through other objects (such as
  26. * io_service::strand objects) that provide additional guarantees.
  27. *
  28. * When asynchronous operations are composed from other asynchronous
  29. * operations, all intermediate handlers should be invoked using the same
  30. * method as the final handler. This is required to ensure that user-defined
  31. * objects are not accessed in a way that may violate the guarantees. This
  32. * hooking function ensures that the invoked method used for the final handler
  33. * is accessible at each intermediate step.
  34. *
  35. * Implement asio_handler_invoke for your own handlers to specify a custom
  36. * invocation strategy.
  37. *
  38. * This default implementation is simply:
  39. * @code
  40. * function();
  41. * @endcode
  42. *
  43. * @par Example
  44. * @code
  45. * class my_handler;
  46. *
  47. * template <typename Function>
  48. * void asio_handler_invoke(Function function, my_handler* context)
  49. * {
  50. * context->strand_.dispatch(function);
  51. * }
  52. * @endcode
  53. */
  54. template <typename Function>
  55. inline void asio_handler_invoke(Function function, ...)
  56. {
  57. function();
  58. }
  59. } // namespace asio
  60. } // namespace boost
  61. #include <boost/asio/detail/pop_options.hpp>
  62. #endif // BOOST_ASIO_HANDLER_INVOKE_HOOK_HPP