handler_invoke_hook.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // handler_invoke_hook.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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 ASIO_HANDLER_INVOKE_HOOK_HPP
  11. #define 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 "asio/detail/push_options.hpp"
  16. namespace asio {
  17. /// Default invoke function for handlers.
  18. /**
  19. * Completion handlers for asynchronous operations are invoked by the
  20. * io_service associated with the corresponding object (e.g. a socket or
  21. * deadline_timer). Certain guarantees are made on when the handler may be
  22. * invoked, in particular that a handler can only be invoked from a thread that
  23. * is currently calling @c run() on the corresponding io_service object.
  24. * Handlers may subsequently be invoked through other objects (such as
  25. * io_service::strand objects) that provide additional guarantees.
  26. *
  27. * When asynchronous operations are composed from other asynchronous
  28. * operations, all intermediate handlers should be invoked using the same
  29. * method as the final handler. This is required to ensure that user-defined
  30. * objects are not accessed in a way that may violate the guarantees. This
  31. * hooking function ensures that the invoked method used for the final handler
  32. * is accessible at each intermediate step.
  33. *
  34. * Implement asio_handler_invoke for your own handlers to specify a custom
  35. * invocation strategy.
  36. *
  37. * This default implementation is simply:
  38. * @code
  39. * function();
  40. * @endcode
  41. *
  42. * @par Example
  43. * @code
  44. * class my_handler;
  45. *
  46. * template <typename Function>
  47. * void asio_handler_invoke(Function function, my_handler* context)
  48. * {
  49. * context->strand_.dispatch(function);
  50. * }
  51. * @endcode
  52. */
  53. template <typename Function>
  54. inline void asio_handler_invoke(Function function, ...)
  55. {
  56. function();
  57. }
  58. } // namespace asio
  59. #include "asio/detail/pop_options.hpp"
  60. #endif // ASIO_HANDLER_INVOKE_HOOK_HPP