random_access_handle_service.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // random_access_handle_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2008 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_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP
  11. #define BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_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/push_options.hpp>
  16. #include <boost/asio/detail/push_options.hpp>
  17. #include <cstddef>
  18. #include <boost/config.hpp>
  19. #include <boost/cstdint.hpp>
  20. #include <boost/asio/detail/pop_options.hpp>
  21. #include <boost/asio/error.hpp>
  22. #include <boost/asio/io_service.hpp>
  23. #include <boost/asio/detail/service_base.hpp>
  24. #include <boost/asio/detail/win_iocp_handle_service.hpp>
  25. #if !defined(BOOST_ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
  26. # if defined(BOOST_ASIO_HAS_IOCP)
  27. # define BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE 1
  28. # endif // defined(BOOST_ASIO_HAS_IOCP)
  29. #endif // !defined(BOOST_ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
  30. #if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \
  31. || defined(GENERATING_DOCUMENTATION)
  32. namespace boost {
  33. namespace asio {
  34. namespace windows {
  35. /// Default service implementation for a random-access handle.
  36. class random_access_handle_service
  37. #if defined(GENERATING_DOCUMENTATION)
  38. : public boost::asio::io_service::service
  39. #else
  40. : public boost::asio::detail::service_base<random_access_handle_service>
  41. #endif
  42. {
  43. public:
  44. #if defined(GENERATING_DOCUMENTATION)
  45. /// The unique service identifier.
  46. static boost::asio::io_service::id id;
  47. #endif
  48. private:
  49. // The type of the platform-specific implementation.
  50. typedef detail::win_iocp_handle_service service_impl_type;
  51. public:
  52. /// The type of a random-access handle implementation.
  53. #if defined(GENERATING_DOCUMENTATION)
  54. typedef implementation_defined implementation_type;
  55. #else
  56. typedef service_impl_type::implementation_type implementation_type;
  57. #endif
  58. /// The native handle type.
  59. #if defined(GENERATING_DOCUMENTATION)
  60. typedef implementation_defined native_type;
  61. #else
  62. typedef service_impl_type::native_type native_type;
  63. #endif
  64. /// Construct a new random-access handle service for the specified io_service.
  65. explicit random_access_handle_service(boost::asio::io_service& io_service)
  66. : boost::asio::detail::service_base<
  67. random_access_handle_service>(io_service),
  68. service_impl_(boost::asio::use_service<service_impl_type>(io_service))
  69. {
  70. }
  71. /// Destroy all user-defined handler objects owned by the service.
  72. void shutdown_service()
  73. {
  74. }
  75. /// Construct a new random-access handle implementation.
  76. void construct(implementation_type& impl)
  77. {
  78. service_impl_.construct(impl);
  79. }
  80. /// Destroy a random-access handle implementation.
  81. void destroy(implementation_type& impl)
  82. {
  83. service_impl_.destroy(impl);
  84. }
  85. /// Assign an existing native handle to a random-access handle.
  86. boost::system::error_code assign(implementation_type& impl,
  87. const native_type& native_handle, boost::system::error_code& ec)
  88. {
  89. return service_impl_.assign(impl, native_handle, ec);
  90. }
  91. /// Determine whether the handle is open.
  92. bool is_open(const implementation_type& impl) const
  93. {
  94. return service_impl_.is_open(impl);
  95. }
  96. /// Close a random-access handle implementation.
  97. boost::system::error_code close(implementation_type& impl,
  98. boost::system::error_code& ec)
  99. {
  100. return service_impl_.close(impl, ec);
  101. }
  102. /// Get the native handle implementation.
  103. native_type native(implementation_type& impl)
  104. {
  105. return service_impl_.native(impl);
  106. }
  107. /// Cancel all asynchronous operations associated with the handle.
  108. boost::system::error_code cancel(implementation_type& impl,
  109. boost::system::error_code& ec)
  110. {
  111. return service_impl_.cancel(impl, ec);
  112. }
  113. /// Write the given data at the specified offset.
  114. template <typename ConstBufferSequence>
  115. std::size_t write_some_at(implementation_type& impl, boost::uint64_t offset,
  116. const ConstBufferSequence& buffers, boost::system::error_code& ec)
  117. {
  118. return service_impl_.write_some_at(impl, offset, buffers, ec);
  119. }
  120. /// Start an asynchronous write at the specified offset.
  121. template <typename ConstBufferSequence, typename WriteHandler>
  122. void async_write_some_at(implementation_type& impl, boost::uint64_t offset,
  123. const ConstBufferSequence& buffers, WriteHandler handler)
  124. {
  125. service_impl_.async_write_some_at(impl, offset, buffers, handler);
  126. }
  127. /// Read some data from the specified offset.
  128. template <typename MutableBufferSequence>
  129. std::size_t read_some_at(implementation_type& impl, boost::uint64_t offset,
  130. const MutableBufferSequence& buffers, boost::system::error_code& ec)
  131. {
  132. return service_impl_.read_some_at(impl, offset, buffers, ec);
  133. }
  134. /// Start an asynchronous read at the specified offset.
  135. template <typename MutableBufferSequence, typename ReadHandler>
  136. void async_read_some_at(implementation_type& impl, boost::uint64_t offset,
  137. const MutableBufferSequence& buffers, ReadHandler handler)
  138. {
  139. service_impl_.async_read_some_at(impl, offset, buffers, handler);
  140. }
  141. private:
  142. // The service that provides the platform-specific implementation.
  143. service_impl_type& service_impl_;
  144. };
  145. } // namespace windows
  146. } // namespace asio
  147. } // namespace boost
  148. #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
  149. // || defined(GENERATING_DOCUMENTATION)
  150. #include <boost/asio/detail/pop_options.hpp>
  151. #endif // BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP