io_control.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // detail/io_control.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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_DETAIL_IO_CONTROL_HPP
  11. #define BOOST_ASIO_DETAIL_IO_CONTROL_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. #include <cstddef>
  17. #include <boost/asio/detail/socket_types.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. namespace io_control {
  23. // I/O control command for getting number of bytes available.
  24. class bytes_readable
  25. {
  26. public:
  27. // Default constructor.
  28. bytes_readable()
  29. : value_(0)
  30. {
  31. }
  32. // Construct with a specific command value.
  33. bytes_readable(std::size_t value)
  34. : value_(static_cast<detail::ioctl_arg_type>(value))
  35. {
  36. }
  37. // Get the name of the IO control command.
  38. int name() const
  39. {
  40. return static_cast<int>(BOOST_ASIO_OS_DEF(FIONREAD));
  41. }
  42. // Set the value of the I/O control command.
  43. void set(std::size_t value)
  44. {
  45. value_ = static_cast<detail::ioctl_arg_type>(value);
  46. }
  47. // Get the current value of the I/O control command.
  48. std::size_t get() const
  49. {
  50. return static_cast<std::size_t>(value_);
  51. }
  52. // Get the address of the command data.
  53. detail::ioctl_arg_type* data()
  54. {
  55. return &value_;
  56. }
  57. // Get the address of the command data.
  58. const detail::ioctl_arg_type* data() const
  59. {
  60. return &value_;
  61. }
  62. private:
  63. detail::ioctl_arg_type value_;
  64. };
  65. } // namespace io_control
  66. } // namespace detail
  67. } // namespace asio
  68. } // namespace boost
  69. #include <boost/asio/detail/pop_options.hpp>
  70. #endif // BOOST_ASIO_DETAIL_IO_CONTROL_HPP