/src/contrib/boost/asio/windows/random_access_handle_service.hpp

http://pythonocc.googlecode.com/ · C++ Header · 182 lines · 123 code · 30 blank · 29 comment · 3 complexity · 89ec271349b6f2927ad519a6e85cd771 MD5 · raw file

  1. //
  2. // random_access_handle_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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_(io_service)
  69. {
  70. }
  71. /// Destroy all user-defined handler objects owned by the service.
  72. void shutdown_service()
  73. {
  74. service_impl_.shutdown_service();
  75. }
  76. /// Construct a new random-access handle implementation.
  77. void construct(implementation_type& impl)
  78. {
  79. service_impl_.construct(impl);
  80. }
  81. /// Destroy a random-access handle implementation.
  82. void destroy(implementation_type& impl)
  83. {
  84. service_impl_.destroy(impl);
  85. }
  86. /// Assign an existing native handle to a random-access handle.
  87. boost::system::error_code assign(implementation_type& impl,
  88. const native_type& native_handle, boost::system::error_code& ec)
  89. {
  90. return service_impl_.assign(impl, native_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 random-access handle implementation.
  98. boost::system::error_code close(implementation_type& impl,
  99. boost::system::error_code& ec)
  100. {
  101. return service_impl_.close(impl, ec);
  102. }
  103. /// Get the native handle implementation.
  104. native_type native(implementation_type& impl)
  105. {
  106. return service_impl_.native(impl);
  107. }
  108. /// Cancel all asynchronous operations associated with the handle.
  109. boost::system::error_code cancel(implementation_type& impl,
  110. boost::system::error_code& ec)
  111. {
  112. return service_impl_.cancel(impl, ec);
  113. }
  114. /// Write the given data at the specified offset.
  115. template <typename ConstBufferSequence>
  116. std::size_t write_some_at(implementation_type& impl, boost::uint64_t offset,
  117. const ConstBufferSequence& buffers, boost::system::error_code& ec)
  118. {
  119. return service_impl_.write_some_at(impl, offset, buffers, ec);
  120. }
  121. /// Start an asynchronous write at the specified offset.
  122. template <typename ConstBufferSequence, typename WriteHandler>
  123. void async_write_some_at(implementation_type& impl, boost::uint64_t offset,
  124. const ConstBufferSequence& buffers, WriteHandler handler)
  125. {
  126. service_impl_.async_write_some_at(impl, offset, buffers, handler);
  127. }
  128. /// Read some data from the specified offset.
  129. template <typename MutableBufferSequence>
  130. std::size_t read_some_at(implementation_type& impl, boost::uint64_t offset,
  131. const MutableBufferSequence& buffers, boost::system::error_code& ec)
  132. {
  133. return service_impl_.read_some_at(impl, offset, buffers, ec);
  134. }
  135. /// Start an asynchronous read at the specified offset.
  136. template <typename MutableBufferSequence, typename ReadHandler>
  137. void async_read_some_at(implementation_type& impl, boost::uint64_t offset,
  138. const MutableBufferSequence& buffers, ReadHandler handler)
  139. {
  140. service_impl_.async_read_some_at(impl, offset, buffers, handler);
  141. }
  142. private:
  143. // The platform-specific implementation.
  144. service_impl_type service_impl_;
  145. };
  146. } // namespace windows
  147. } // namespace asio
  148. } // namespace boost
  149. #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
  150. // || defined(GENERATING_DOCUMENTATION)
  151. #include <boost/asio/detail/pop_options.hpp>
  152. #endif // BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP