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