descriptor_base.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // posix/descriptor_base.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_DESCRIPTOR_BASE_HPP
  11. #define ASIO_POSIX_DESCRIPTOR_BASE_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 "asio/detail/io_control.hpp"
  19. #include "asio/detail/socket_option.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace posix {
  23. /// The descriptor_base class is used as a base for the basic_stream_descriptor
  24. /// class template so that we have a common place to define the associated
  25. /// IO control commands.
  26. class descriptor_base
  27. {
  28. public:
  29. /// IO control command to set the blocking mode of the descriptor.
  30. /**
  31. * Implements the FIONBIO IO control command.
  32. *
  33. * @par Example
  34. * @code
  35. * asio::posix::stream_descriptor descriptor(io_service);
  36. * ...
  37. * asio::descriptor_base::non_blocking_io command(true);
  38. * descriptor.io_control(command);
  39. * @endcode
  40. *
  41. * @par Concepts:
  42. * IoControlCommand.
  43. */
  44. #if defined(GENERATING_DOCUMENTATION)
  45. typedef implementation_defined non_blocking_io;
  46. #else
  47. typedef asio::detail::io_control::non_blocking_io non_blocking_io;
  48. #endif
  49. /// IO control command to get the amount of data that can be read without
  50. /// blocking.
  51. /**
  52. * Implements the FIONREAD IO control command.
  53. *
  54. * @par Example
  55. * @code
  56. * asio::posix::stream_descriptor descriptor(io_service);
  57. * ...
  58. * asio::descriptor_base::bytes_readable command(true);
  59. * descriptor.io_control(command);
  60. * std::size_t bytes_readable = command.get();
  61. * @endcode
  62. *
  63. * @par Concepts:
  64. * IoControlCommand.
  65. */
  66. #if defined(GENERATING_DOCUMENTATION)
  67. typedef implementation_defined bytes_readable;
  68. #else
  69. typedef asio::detail::io_control::bytes_readable bytes_readable;
  70. #endif
  71. protected:
  72. /// Protected destructor to prevent deletion through this type.
  73. ~descriptor_base()
  74. {
  75. }
  76. };
  77. } // namespace posix
  78. } // namespace asio
  79. #include "asio/detail/pop_options.hpp"
  80. #endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
  81. // || defined(GENERATING_DOCUMENTATION)
  82. #endif // ASIO_POSIX_DESCRIPTOR_BASE_HPP