object_handle_service.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // windows/object_handle_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Copyright (c) 2011 Boris Schaeling (boris@highscore.de)
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
  12. #define BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include <boost/asio/detail/config.hpp>
  17. #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  18. #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
  19. || defined(GENERATING_DOCUMENTATION)
  20. #include <boost/asio/async_result.hpp>
  21. #include <boost/asio/detail/win_object_handle_service.hpp>
  22. #include <boost/asio/error.hpp>
  23. #include <boost/asio/io_context.hpp>
  24. #include <boost/asio/detail/push_options.hpp>
  25. namespace boost {
  26. namespace asio {
  27. namespace windows {
  28. /// Default service implementation for an object handle.
  29. class object_handle_service
  30. #if defined(GENERATING_DOCUMENTATION)
  31. : public boost::asio::io_context::service
  32. #else
  33. : public boost::asio::detail::service_base<object_handle_service>
  34. #endif
  35. {
  36. public:
  37. #if defined(GENERATING_DOCUMENTATION)
  38. /// The unique service identifier.
  39. static boost::asio::io_context::id id;
  40. #endif
  41. private:
  42. // The type of the platform-specific implementation.
  43. typedef detail::win_object_handle_service service_impl_type;
  44. public:
  45. /// The type of an object handle implementation.
  46. #if defined(GENERATING_DOCUMENTATION)
  47. typedef implementation_defined implementation_type;
  48. #else
  49. typedef service_impl_type::implementation_type implementation_type;
  50. #endif
  51. /// The native handle type.
  52. #if defined(GENERATING_DOCUMENTATION)
  53. typedef implementation_defined native_handle_type;
  54. #else
  55. typedef service_impl_type::native_handle_type native_handle_type;
  56. #endif
  57. /// Construct a new object handle service for the specified io_context.
  58. explicit object_handle_service(boost::asio::io_context& io_context)
  59. : boost::asio::detail::service_base<object_handle_service>(io_context),
  60. service_impl_(io_context)
  61. {
  62. }
  63. /// Construct a new object handle implementation.
  64. void construct(implementation_type& impl)
  65. {
  66. service_impl_.construct(impl);
  67. }
  68. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  69. /// Move-construct a new object handle implementation.
  70. void move_construct(implementation_type& impl,
  71. implementation_type& other_impl)
  72. {
  73. service_impl_.move_construct(impl, other_impl);
  74. }
  75. /// Move-assign from another object handle implementation.
  76. void move_assign(implementation_type& impl,
  77. object_handle_service& other_service,
  78. implementation_type& other_impl)
  79. {
  80. service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
  81. }
  82. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  83. /// Destroy an object handle implementation.
  84. void destroy(implementation_type& impl)
  85. {
  86. service_impl_.destroy(impl);
  87. }
  88. /// Assign an existing native handle to an object handle.
  89. BOOST_ASIO_SYNC_OP_VOID assign(implementation_type& impl,
  90. const native_handle_type& handle, boost::system::error_code& ec)
  91. {
  92. service_impl_.assign(impl, handle, ec);
  93. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  94. }
  95. /// Determine whether the handle is open.
  96. bool is_open(const implementation_type& impl) const
  97. {
  98. return service_impl_.is_open(impl);
  99. }
  100. /// Close an object handle implementation.
  101. BOOST_ASIO_SYNC_OP_VOID close(implementation_type& impl,
  102. boost::system::error_code& ec)
  103. {
  104. service_impl_.close(impl, ec);
  105. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  106. }
  107. /// Get the native handle implementation.
  108. native_handle_type native_handle(implementation_type& impl)
  109. {
  110. return service_impl_.native_handle(impl);
  111. }
  112. /// Cancel all asynchronous operations associated with the handle.
  113. BOOST_ASIO_SYNC_OP_VOID cancel(implementation_type& impl,
  114. boost::system::error_code& ec)
  115. {
  116. service_impl_.cancel(impl, ec);
  117. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  118. }
  119. // Wait for a signaled state.
  120. void wait(implementation_type& impl, boost::system::error_code& ec)
  121. {
  122. service_impl_.wait(impl, ec);
  123. }
  124. /// Start an asynchronous wait.
  125. template <typename WaitHandler>
  126. BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
  127. void (boost::system::error_code))
  128. async_wait(implementation_type& impl,
  129. BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
  130. {
  131. boost::asio::async_completion<WaitHandler,
  132. void (boost::system::error_code)> init(handler);
  133. service_impl_.async_wait(impl, init.completion_handler);
  134. return init.result.get();
  135. }
  136. private:
  137. // Destroy all user-defined handler objects owned by the service.
  138. void shutdown()
  139. {
  140. service_impl_.shutdown();
  141. }
  142. // The platform-specific implementation.
  143. service_impl_type service_impl_;
  144. };
  145. } // namespace windows
  146. } // namespace asio
  147. } // namespace boost
  148. #include <boost/asio/detail/pop_options.hpp>
  149. #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
  150. // || defined(GENERATING_DOCUMENTATION)
  151. #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
  152. #endif // BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP