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.

overlapped_ptr.hpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // windows/overlapped_ptr.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_OVERLAPPED_PTR_HPP
  11. #define ASIO_WINDOWS_OVERLAPPED_PTR_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_OVERLAPPED_PTR) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include "asio/detail/noncopyable.hpp"
  19. #include "asio/detail/win_iocp_overlapped_ptr.hpp"
  20. #include "asio/io_context.hpp"
  21. #include "asio/detail/push_options.hpp"
  22. namespace asio {
  23. namespace windows {
  24. /// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O.
  25. /**
  26. * A special-purpose smart pointer used to wrap an application handler so that
  27. * it can be passed as the LPOVERLAPPED argument to overlapped I/O functions.
  28. *
  29. * @par Thread Safety
  30. * @e Distinct @e objects: Safe.@n
  31. * @e Shared @e objects: Unsafe.
  32. */
  33. class overlapped_ptr
  34. : private noncopyable
  35. {
  36. public:
  37. /// Construct an empty overlapped_ptr.
  38. overlapped_ptr()
  39. : impl_()
  40. {
  41. }
  42. /// Construct an overlapped_ptr to contain the specified handler.
  43. template <typename ExecutionContext, typename Handler>
  44. explicit overlapped_ptr(ExecutionContext& context,
  45. ASIO_MOVE_ARG(Handler) handler,
  46. typename enable_if<
  47. is_convertible<ExecutionContext&, execution_context&>::value
  48. >::type* = 0)
  49. : impl_(context.get_executor(), ASIO_MOVE_CAST(Handler)(handler))
  50. {
  51. }
  52. /// Construct an overlapped_ptr to contain the specified handler.
  53. template <typename Executor, typename Handler>
  54. explicit overlapped_ptr(const Executor& ex,
  55. ASIO_MOVE_ARG(Handler) handler,
  56. typename enable_if<
  57. is_executor<Executor>::value
  58. >::type* = 0)
  59. : impl_(ex, ASIO_MOVE_CAST(Handler)(handler))
  60. {
  61. }
  62. /// Destructor automatically frees the OVERLAPPED object unless released.
  63. ~overlapped_ptr()
  64. {
  65. }
  66. /// Reset to empty.
  67. void reset()
  68. {
  69. impl_.reset();
  70. }
  71. /// Reset to contain the specified handler, freeing any current OVERLAPPED
  72. /// object.
  73. template <typename ExecutionContext, typename Handler>
  74. void reset(ExecutionContext& context, ASIO_MOVE_ARG(Handler) handler,
  75. typename enable_if<
  76. is_convertible<ExecutionContext&, execution_context&>::value
  77. >::type* = 0)
  78. {
  79. impl_.reset(context.get_executor(), ASIO_MOVE_CAST(Handler)(handler));
  80. }
  81. /// Reset to contain the specified handler, freeing any current OVERLAPPED
  82. /// object.
  83. template <typename Executor, typename Handler>
  84. void reset(const Executor& ex, ASIO_MOVE_ARG(Handler) handler,
  85. typename enable_if<
  86. is_executor<Executor>::value
  87. >::type* = 0)
  88. {
  89. impl_.reset(ex, ASIO_MOVE_CAST(Handler)(handler));
  90. }
  91. /// Get the contained OVERLAPPED object.
  92. OVERLAPPED* get()
  93. {
  94. return impl_.get();
  95. }
  96. /// Get the contained OVERLAPPED object.
  97. const OVERLAPPED* get() const
  98. {
  99. return impl_.get();
  100. }
  101. /// Release ownership of the OVERLAPPED object.
  102. OVERLAPPED* release()
  103. {
  104. return impl_.release();
  105. }
  106. /// Post completion notification for overlapped operation. Releases ownership.
  107. void complete(const asio::error_code& ec,
  108. std::size_t bytes_transferred)
  109. {
  110. impl_.complete(ec, bytes_transferred);
  111. }
  112. private:
  113. detail::win_iocp_overlapped_ptr impl_;
  114. };
  115. } // namespace windows
  116. } // namespace asio
  117. #include "asio/detail/pop_options.hpp"
  118. #endif // defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
  119. // || defined(GENERATING_DOCUMENTATION)
  120. #endif // ASIO_WINDOWS_OVERLAPPED_PTR_HPP