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 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // windows/overlapped_ptr.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_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 Handler>
  44. explicit overlapped_ptr(asio::io_context& io_context,
  45. ASIO_MOVE_ARG(Handler) handler)
  46. : impl_(io_context, ASIO_MOVE_CAST(Handler)(handler))
  47. {
  48. }
  49. /// Destructor automatically frees the OVERLAPPED object unless released.
  50. ~overlapped_ptr()
  51. {
  52. }
  53. /// Reset to empty.
  54. void reset()
  55. {
  56. impl_.reset();
  57. }
  58. /// Reset to contain the specified handler, freeing any current OVERLAPPED
  59. /// object.
  60. template <typename Handler>
  61. void reset(asio::io_context& io_context,
  62. ASIO_MOVE_ARG(Handler) handler)
  63. {
  64. impl_.reset(io_context, ASIO_MOVE_CAST(Handler)(handler));
  65. }
  66. /// Get the contained OVERLAPPED object.
  67. OVERLAPPED* get()
  68. {
  69. return impl_.get();
  70. }
  71. /// Get the contained OVERLAPPED object.
  72. const OVERLAPPED* get() const
  73. {
  74. return impl_.get();
  75. }
  76. /// Release ownership of the OVERLAPPED object.
  77. OVERLAPPED* release()
  78. {
  79. return impl_.release();
  80. }
  81. /// Post completion notification for overlapped operation. Releases ownership.
  82. void complete(const asio::error_code& ec,
  83. std::size_t bytes_transferred)
  84. {
  85. impl_.complete(ec, bytes_transferred);
  86. }
  87. private:
  88. detail::win_iocp_overlapped_ptr impl_;
  89. };
  90. } // namespace windows
  91. } // namespace asio
  92. #include "asio/detail/pop_options.hpp"
  93. #endif // defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
  94. // || defined(GENERATING_DOCUMENTATION)
  95. #endif // ASIO_WINDOWS_OVERLAPPED_PTR_HPP