Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.7KB

  1. //
  2. // windows/stream_handle_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 ASIO_WINDOWS_STREAM_HANDLE_SERVICE_HPP
  11. #define ASIO_WINDOWS_STREAM_HANDLE_SERVICE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_HAS_WINDOWS_STREAM_HANDLE) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include <cstddef>
  19. #include "asio/async_result.hpp"
  20. #include "asio/detail/win_iocp_handle_service.hpp"
  21. #include "asio/error.hpp"
  22. #include "asio/io_context.hpp"
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace windows {
  26. /// Default service implementation for a stream handle.
  27. class stream_handle_service
  28. #if defined(GENERATING_DOCUMENTATION)
  29. : public asio::io_context::service
  30. #else
  31. : public asio::detail::service_base<stream_handle_service>
  32. #endif
  33. {
  34. public:
  35. #if defined(GENERATING_DOCUMENTATION)
  36. /// The unique service identifier.
  37. static asio::io_context::id id;
  38. #endif
  39. private:
  40. // The type of the platform-specific implementation.
  41. typedef detail::win_iocp_handle_service service_impl_type;
  42. public:
  43. /// The type of a stream handle implementation.
  44. #if defined(GENERATING_DOCUMENTATION)
  45. typedef implementation_defined implementation_type;
  46. #else
  47. typedef service_impl_type::implementation_type implementation_type;
  48. #endif
  49. /// The native handle type.
  50. #if defined(GENERATING_DOCUMENTATION)
  51. typedef implementation_defined native_handle_type;
  52. #else
  53. typedef service_impl_type::native_handle_type native_handle_type;
  54. #endif
  55. /// Construct a new stream handle service for the specified io_context.
  56. explicit stream_handle_service(asio::io_context& io_context)
  57. : asio::detail::service_base<stream_handle_service>(io_context),
  58. service_impl_(io_context)
  59. {
  60. }
  61. /// Construct a new stream handle implementation.
  62. void construct(implementation_type& impl)
  63. {
  64. service_impl_.construct(impl);
  65. }
  66. #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  67. /// Move-construct a new stream handle implementation.
  68. void move_construct(implementation_type& impl,
  69. implementation_type& other_impl)
  70. {
  71. service_impl_.move_construct(impl, other_impl);
  72. }
  73. /// Move-assign from another stream handle implementation.
  74. void move_assign(implementation_type& impl,
  75. stream_handle_service& other_service,
  76. implementation_type& other_impl)
  77. {
  78. service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
  79. }
  80. #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  81. /// Destroy a stream handle implementation.
  82. void destroy(implementation_type& impl)
  83. {
  84. service_impl_.destroy(impl);
  85. }
  86. /// Assign an existing native handle to a stream handle.
  87. asio::error_code assign(implementation_type& impl,
  88. const native_handle_type& handle, asio::error_code& ec)
  89. {
  90. return service_impl_.assign(impl, handle, ec);
  91. }
  92. /// Determine whether the handle is open.
  93. bool is_open(const implementation_type& impl) const
  94. {
  95. return service_impl_.is_open(impl);
  96. }
  97. /// Close a stream handle implementation.
  98. asio::error_code close(implementation_type& impl,
  99. asio::error_code& ec)
  100. {
  101. return service_impl_.close(impl, ec);
  102. }
  103. /// Get the native handle implementation.
  104. native_handle_type native_handle(implementation_type& impl)
  105. {
  106. return service_impl_.native_handle(impl);
  107. }
  108. /// Cancel all asynchronous operations associated with the handle.
  109. asio::error_code cancel(implementation_type& impl,
  110. asio::error_code& ec)
  111. {
  112. return service_impl_.cancel(impl, ec);
  113. }
  114. /// Write the given data to the stream.
  115. template <typename ConstBufferSequence>
  116. std::size_t write_some(implementation_type& impl,
  117. const ConstBufferSequence& buffers, asio::error_code& ec)
  118. {
  119. return service_impl_.write_some(impl, buffers, ec);
  120. }
  121. /// Start an asynchronous write.
  122. template <typename ConstBufferSequence, typename WriteHandler>
  123. ASIO_INITFN_RESULT_TYPE(WriteHandler,
  124. void (asio::error_code, std::size_t))
  125. async_write_some(implementation_type& impl,
  126. const ConstBufferSequence& buffers,
  127. ASIO_MOVE_ARG(WriteHandler) handler)
  128. {
  129. asio::async_completion<WriteHandler,
  130. void (asio::error_code, std::size_t)> init(handler);
  131. service_impl_.async_write_some(impl, buffers, init.handler);
  132. return init.result.get();
  133. }
  134. /// Read some data from the stream.
  135. template <typename MutableBufferSequence>
  136. std::size_t read_some(implementation_type& impl,
  137. const MutableBufferSequence& buffers, asio::error_code& ec)
  138. {
  139. return service_impl_.read_some(impl, buffers, ec);
  140. }
  141. /// Start an asynchronous read.
  142. template <typename MutableBufferSequence, typename ReadHandler>
  143. ASIO_INITFN_RESULT_TYPE(ReadHandler,
  144. void (asio::error_code, std::size_t))
  145. async_read_some(implementation_type& impl,
  146. const MutableBufferSequence& buffers,
  147. ASIO_MOVE_ARG(ReadHandler) handler)
  148. {
  149. asio::async_completion<ReadHandler,
  150. void (asio::error_code, std::size_t)> init(handler);
  151. service_impl_.async_read_some(impl, buffers, init.handler);
  152. return init.result.get();
  153. }
  154. private:
  155. // Destroy all user-defined handler objects owned by the service.
  156. void shutdown()
  157. {
  158. service_impl_.shutdown();
  159. }
  160. // The platform-specific implementation.
  161. service_impl_type service_impl_;
  162. };
  163. } // namespace windows
  164. } // namespace asio
  165. #include "asio/detail/pop_options.hpp"
  166. #endif // defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
  167. // || defined(GENERATING_DOCUMENTATION)
  168. #endif // ASIO_WINDOWS_STREAM_HANDLE_SERVICE_HPP