descriptor_base.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // posix/descriptor_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_POSIX_DESCRIPTOR_BASE_HPP
  11. #define BOOST_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 <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include <boost/asio/detail/io_control.hpp>
  19. #include <boost/asio/detail/socket_option.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace posix {
  24. /// The descriptor_base class is used as a base for the descriptor class as a
  25. /// place to define the associated IO control commands.
  26. class descriptor_base
  27. {
  28. public:
  29. /// Wait types.
  30. /**
  31. * For use with descriptor::wait() and descriptor::async_wait().
  32. */
  33. enum wait_type
  34. {
  35. /// Wait for a descriptor to become ready to read.
  36. wait_read,
  37. /// Wait for a descriptor to become ready to write.
  38. wait_write,
  39. /// Wait for a descriptor to have error conditions pending.
  40. wait_error
  41. };
  42. /// IO control command to get the amount of data that can be read without
  43. /// blocking.
  44. /**
  45. * Implements the FIONREAD IO control command.
  46. *
  47. * @par Example
  48. * @code
  49. * boost::asio::posix::stream_descriptor descriptor(my_context);
  50. * ...
  51. * boost::asio::descriptor_base::bytes_readable command(true);
  52. * descriptor.io_control(command);
  53. * std::size_t bytes_readable = command.get();
  54. * @endcode
  55. *
  56. * @par Concepts:
  57. * IoControlCommand.
  58. */
  59. #if defined(GENERATING_DOCUMENTATION)
  60. typedef implementation_defined bytes_readable;
  61. #else
  62. typedef boost::asio::detail::io_control::bytes_readable bytes_readable;
  63. #endif
  64. protected:
  65. /// Protected destructor to prevent deletion through this type.
  66. ~descriptor_base()
  67. {
  68. }
  69. };
  70. } // namespace posix
  71. } // namespace asio
  72. } // namespace boost
  73. #include <boost/asio/detail/pop_options.hpp>
  74. #endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
  75. // || defined(GENERATING_DOCUMENTATION)
  76. #endif // BOOST_ASIO_POSIX_DESCRIPTOR_BASE_HPP