00001 // 00002 // io_control.hpp 00003 // ~~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) 00006 // 00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 00011 #ifndef ASIO_DETAIL_IO_CONTROL_HPP 00012 #define ASIO_DETAIL_IO_CONTROL_HPP 00013 00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 00015 # pragma once 00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 00017 00018 #include "asio/detail/push_options.hpp" 00019 00020 #include "asio/detail/push_options.hpp" 00021 #include <cstddef> 00022 #include <boost/config.hpp> 00023 #include "asio/detail/pop_options.hpp" 00024 00025 #include "asio/detail/socket_types.hpp" 00026 00027 namespace asio { 00028 namespace detail { 00029 namespace io_control { 00030 00031 // IO control command for non-blocking I/O. 00032 class non_blocking_io 00033 { 00034 public: 00035 // Default constructor. 00036 non_blocking_io() 00037 : value_(0) 00038 { 00039 } 00040 00041 // Construct with a specific command value. 00042 non_blocking_io(bool value) 00043 : value_(value ? 1 : 0) 00044 { 00045 } 00046 00047 // Get the name of the IO control command. 00048 int name() const 00049 { 00050 return FIONBIO; 00051 } 00052 00053 // Set the value of the I/O control command. 00054 void set(bool value) 00055 { 00056 value_ = value ? 1 : 0; 00057 } 00058 00059 // Get the current value of the I/O control command. 00060 bool get() const 00061 { 00062 return value_ != 0; 00063 } 00064 00065 // Get the address of the command data. 00066 detail::ioctl_arg_type* data() 00067 { 00068 return &value_; 00069 } 00070 00071 // Get the address of the command data. 00072 const detail::ioctl_arg_type* data() const 00073 { 00074 return &value_; 00075 } 00076 00077 private: 00078 detail::ioctl_arg_type value_; 00079 }; 00080 00081 // I/O control command for getting number of bytes available. 00082 class bytes_readable 00083 { 00084 public: 00085 // Default constructor. 00086 bytes_readable() 00087 : value_(0) 00088 { 00089 } 00090 00091 // Construct with a specific command value. 00092 bytes_readable(std::size_t value) 00093 : value_(static_cast<detail::ioctl_arg_type>(value)) 00094 { 00095 } 00096 00097 // Get the name of the IO control command. 00098 int name() const 00099 { 00100 return FIONREAD; 00101 } 00102 00103 // Set the value of the I/O control command. 00104 void set(std::size_t value) 00105 { 00106 value_ = static_cast<detail::ioctl_arg_type>(value); 00107 } 00108 00109 // Get the current value of the I/O control command. 00110 std::size_t get() const 00111 { 00112 return static_cast<std::size_t>(value_); 00113 } 00114 00115 // Get the address of the command data. 00116 detail::ioctl_arg_type* data() 00117 { 00118 return &value_; 00119 } 00120 00121 // Get the address of the command data. 00122 const detail::ioctl_arg_type* data() const 00123 { 00124 return &value_; 00125 } 00126 00127 private: 00128 detail::ioctl_arg_type value_; 00129 }; 00130 00131 } // namespace io_control 00132 } // namespace detail 00133 } // namespace asio 00134 00135 #include "asio/detail/pop_options.hpp" 00136 00137 #endif // ASIO_DETAIL_IO_CONTROL_HPP