10ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
20ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// detail/io_control.hpp
30ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// ~~~~~~~~~~~~~~~~~~~~~
40ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
50ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
60ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
70ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Distributed under the Boost Software License, Version 1.0. (See accompanying
80ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
90ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#ifndef ASIO_DETAIL_IO_CONTROL_HPP
120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#define ASIO_DETAIL_IO_CONTROL_HPP
130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/config.hpp"
160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include <cstddef>
170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/socket_types.hpp"
180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/push_options.hpp"
200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace asio {
220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace detail {
230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace io_control {
240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// IO control command for non-blocking I/O.
260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass non_blocking_io
270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiepublic:
290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Default constructor.
300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  non_blocking_io()
310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : value_(0)
320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Construct with a specific command value.
360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  non_blocking_io(bool value)
370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : value_(value ? 1 : 0)
380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the name of the IO control command.
420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  int name() const
430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return static_cast<int>(ASIO_OS_DEF(FIONBIO));
450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Set the value of the I/O control command.
480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void set(bool value)
490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    value_ = value ? 1 : 0;
510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the current value of the I/O control command.
540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  bool get() const
550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return value_ != 0;
570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the address of the command data.
600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  detail::ioctl_arg_type* data()
610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return &value_;
630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the address of the command data.
660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  const detail::ioctl_arg_type* data() const
670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return &value_;
690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieprivate:
720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  detail::ioctl_arg_type value_;
730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
740ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
750ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// I/O control command for getting number of bytes available.
760ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass bytes_readable
770ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
780ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiepublic:
790ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Default constructor.
800ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  bytes_readable()
810ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : value_(0)
820ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
830ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
840ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
850ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Construct with a specific command value.
860ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  bytes_readable(std::size_t value)
870ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    : value_(static_cast<detail::ioctl_arg_type>(value))
880ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
890ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
900ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
910ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the name of the IO control command.
920ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  int name() const
930ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
940ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return static_cast<int>(ASIO_OS_DEF(FIONREAD));
950ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
960ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
970ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Set the value of the I/O control command.
980ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  void set(std::size_t value)
990ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1000ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    value_ = static_cast<detail::ioctl_arg_type>(value);
1010ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1020ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1030ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the current value of the I/O control command.
1040ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  std::size_t get() const
1050ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1060ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return static_cast<std::size_t>(value_);
1070ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1080ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1090ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the address of the command data.
1100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  detail::ioctl_arg_type* data()
1110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return &value_;
1130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the address of the command data.
1160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  const detail::ioctl_arg_type* data() const
1170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
1180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return &value_;
1190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
1200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieprivate:
1220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  detail::ioctl_arg_type value_;
1230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
1240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace io_control
1260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace detail
1270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace asio
1280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/pop_options.hpp"
1300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
1310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#endif // ASIO_DETAIL_IO_CONTROL_HPP
132