signal_set_service.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // signal_set_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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_SIGNAL_SET_SERVICE_HPP
  11. #define BOOST_ASIO_SIGNAL_SET_SERVICE_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/config.hpp>
  16. #include <boost/asio/async_result.hpp>
  17. #include <boost/asio/detail/signal_set_service.hpp>
  18. #include <boost/asio/error.hpp>
  19. #include <boost/asio/io_service.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. /// Default service implementation for a signal set.
  24. class signal_set_service
  25. #if defined(GENERATING_DOCUMENTATION)
  26. : public boost::asio::io_service::service
  27. #else
  28. : public boost::asio::detail::service_base<signal_set_service>
  29. #endif
  30. {
  31. public:
  32. #if defined(GENERATING_DOCUMENTATION)
  33. /// The unique service identifier.
  34. static boost::asio::io_service::id id;
  35. #endif
  36. public:
  37. /// The type of a signal set implementation.
  38. #if defined(GENERATING_DOCUMENTATION)
  39. typedef implementation_defined implementation_type;
  40. #else
  41. typedef detail::signal_set_service::implementation_type implementation_type;
  42. #endif
  43. /// Construct a new signal set service for the specified io_service.
  44. explicit signal_set_service(boost::asio::io_service& io_service)
  45. : boost::asio::detail::service_base<signal_set_service>(io_service),
  46. service_impl_(io_service)
  47. {
  48. }
  49. /// Construct a new signal set implementation.
  50. void construct(implementation_type& impl)
  51. {
  52. service_impl_.construct(impl);
  53. }
  54. /// Destroy a signal set implementation.
  55. void destroy(implementation_type& impl)
  56. {
  57. service_impl_.destroy(impl);
  58. }
  59. /// Add a signal to a signal_set.
  60. boost::system::error_code add(implementation_type& impl,
  61. int signal_number, boost::system::error_code& ec)
  62. {
  63. return service_impl_.add(impl, signal_number, ec);
  64. }
  65. /// Remove a signal to a signal_set.
  66. boost::system::error_code remove(implementation_type& impl,
  67. int signal_number, boost::system::error_code& ec)
  68. {
  69. return service_impl_.remove(impl, signal_number, ec);
  70. }
  71. /// Remove all signals from a signal_set.
  72. boost::system::error_code clear(implementation_type& impl,
  73. boost::system::error_code& ec)
  74. {
  75. return service_impl_.clear(impl, ec);
  76. }
  77. /// Cancel all operations associated with the signal set.
  78. boost::system::error_code cancel(implementation_type& impl,
  79. boost::system::error_code& ec)
  80. {
  81. return service_impl_.cancel(impl, ec);
  82. }
  83. // Start an asynchronous operation to wait for a signal to be delivered.
  84. template <typename SignalHandler>
  85. BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler,
  86. void (boost::system::error_code, int))
  87. async_wait(implementation_type& impl,
  88. BOOST_ASIO_MOVE_ARG(SignalHandler) handler)
  89. {
  90. detail::async_result_init<
  91. SignalHandler, void (boost::system::error_code, int)> init(
  92. BOOST_ASIO_MOVE_CAST(SignalHandler)(handler));
  93. service_impl_.async_wait(impl, init.handler);
  94. return init.result.get();
  95. }
  96. private:
  97. // Destroy all user-defined handler objects owned by the service.
  98. void shutdown_service()
  99. {
  100. service_impl_.shutdown_service();
  101. }
  102. // Perform any fork-related housekeeping.
  103. void fork_service(boost::asio::io_service::fork_event event)
  104. {
  105. service_impl_.fork_service(event);
  106. }
  107. // The platform-specific implementation.
  108. detail::signal_set_service service_impl_;
  109. };
  110. } // namespace asio
  111. } // namespace boost
  112. #include <boost/asio/detail/pop_options.hpp>
  113. #endif // BOOST_ASIO_SIGNAL_SET_SERVICE_HPP