stream_descriptor_service.hpp 5.0 KB

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