• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // detail/io_control.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 
11 #ifndef ASIO_DETAIL_IO_CONTROL_HPP
12 #define ASIO_DETAIL_IO_CONTROL_HPP
13 
14 
15 #include "asio/detail/config.hpp"
16 #include <cstddef>
17 #include "asio/detail/socket_types.hpp"
18 
19 #include "asio/detail/push_options.hpp"
20 
21 namespace asio {
22 namespace detail {
23 namespace io_control {
24 
25 // IO control command for non-blocking I/O.
26 class non_blocking_io
27 {
28 public:
29   // Default constructor.
non_blocking_io()30   non_blocking_io()
31     : value_(0)
32   {
33   }
34 
35   // Construct with a specific command value.
non_blocking_io(bool value)36   non_blocking_io(bool value)
37     : value_(value ? 1 : 0)
38   {
39   }
40 
41   // Get the name of the IO control command.
name() const42   int name() const
43   {
44     return static_cast<int>(ASIO_OS_DEF(FIONBIO));
45   }
46 
47   // Set the value of the I/O control command.
set(bool value)48   void set(bool value)
49   {
50     value_ = value ? 1 : 0;
51   }
52 
53   // Get the current value of the I/O control command.
get() const54   bool get() const
55   {
56     return value_ != 0;
57   }
58 
59   // Get the address of the command data.
data()60   detail::ioctl_arg_type* data()
61   {
62     return &value_;
63   }
64 
65   // Get the address of the command data.
data() const66   const detail::ioctl_arg_type* data() const
67   {
68     return &value_;
69   }
70 
71 private:
72   detail::ioctl_arg_type value_;
73 };
74 
75 // I/O control command for getting number of bytes available.
76 class bytes_readable
77 {
78 public:
79   // Default constructor.
bytes_readable()80   bytes_readable()
81     : value_(0)
82   {
83   }
84 
85   // Construct with a specific command value.
bytes_readable(std::size_t value)86   bytes_readable(std::size_t value)
87     : value_(static_cast<detail::ioctl_arg_type>(value))
88   {
89   }
90 
91   // Get the name of the IO control command.
name() const92   int name() const
93   {
94     return static_cast<int>(ASIO_OS_DEF(FIONREAD));
95   }
96 
97   // Set the value of the I/O control command.
set(std::size_t value)98   void set(std::size_t value)
99   {
100     value_ = static_cast<detail::ioctl_arg_type>(value);
101   }
102 
103   // Get the current value of the I/O control command.
get() const104   std::size_t get() const
105   {
106     return static_cast<std::size_t>(value_);
107   }
108 
109   // Get the address of the command data.
data()110   detail::ioctl_arg_type* data()
111   {
112     return &value_;
113   }
114 
115   // Get the address of the command data.
data() const116   const detail::ioctl_arg_type* data() const
117   {
118     return &value_;
119   }
120 
121 private:
122   detail::ioctl_arg_type value_;
123 };
124 
125 } // namespace io_control
126 } // namespace detail
127 } // namespace asio
128 
129 #include "asio/detail/pop_options.hpp"
130 
131 #endif // ASIO_DETAIL_IO_CONTROL_HPP
132