stream_descriptor_service.hpp 5.4 KB

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