descriptor_ops.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // detail/descriptor_ops.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_DESCRIPTOR_OPS_HPP
  11. #define BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_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. #if !defined(BOOST_ASIO_WINDOWS) \
  17. && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
  18. && !defined(__CYGWIN__)
  19. #include <cstddef>
  20. #include <boost/asio/error.hpp>
  21. #include <boost/system/error_code.hpp>
  22. #include <boost/asio/detail/socket_types.hpp>
  23. #include <boost/asio/detail/push_options.hpp>
  24. namespace boost {
  25. namespace asio {
  26. namespace detail {
  27. namespace descriptor_ops {
  28. // Descriptor state bits.
  29. enum
  30. {
  31. // The user wants a non-blocking descriptor.
  32. user_set_non_blocking = 1,
  33. // The descriptor has been set non-blocking.
  34. internal_non_blocking = 2,
  35. // Helper "state" used to determine whether the descriptor is non-blocking.
  36. non_blocking = user_set_non_blocking | internal_non_blocking,
  37. // The descriptor may have been dup()-ed.
  38. possible_dup = 4
  39. };
  40. typedef unsigned char state_type;
  41. template <typename ReturnType>
  42. inline ReturnType error_wrapper(ReturnType return_value,
  43. boost::system::error_code& ec)
  44. {
  45. ec = boost::system::error_code(errno,
  46. boost::asio::error::get_system_category());
  47. return return_value;
  48. }
  49. BOOST_ASIO_DECL int open(const char* path, int flags,
  50. boost::system::error_code& ec);
  51. BOOST_ASIO_DECL int close(int d, state_type& state,
  52. boost::system::error_code& ec);
  53. BOOST_ASIO_DECL bool set_user_non_blocking(int d,
  54. state_type& state, bool value, boost::system::error_code& ec);
  55. BOOST_ASIO_DECL bool set_internal_non_blocking(int d,
  56. state_type& state, bool value, boost::system::error_code& ec);
  57. typedef iovec buf;
  58. BOOST_ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs,
  59. std::size_t count, bool all_empty, boost::system::error_code& ec);
  60. BOOST_ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count,
  61. boost::system::error_code& ec, std::size_t& bytes_transferred);
  62. BOOST_ASIO_DECL std::size_t sync_write(int d, state_type state,
  63. const buf* bufs, std::size_t count, bool all_empty,
  64. boost::system::error_code& ec);
  65. BOOST_ASIO_DECL bool non_blocking_write(int d,
  66. const buf* bufs, std::size_t count,
  67. boost::system::error_code& ec, std::size_t& bytes_transferred);
  68. BOOST_ASIO_DECL int ioctl(int d, state_type& state, long cmd,
  69. ioctl_arg_type* arg, boost::system::error_code& ec);
  70. BOOST_ASIO_DECL int fcntl(int d, int cmd, boost::system::error_code& ec);
  71. BOOST_ASIO_DECL int fcntl(int d, int cmd,
  72. long arg, boost::system::error_code& ec);
  73. BOOST_ASIO_DECL int poll_read(int d,
  74. state_type state, boost::system::error_code& ec);
  75. BOOST_ASIO_DECL int poll_write(int d,
  76. state_type state, boost::system::error_code& ec);
  77. BOOST_ASIO_DECL int poll_error(int d,
  78. state_type state, boost::system::error_code& ec);
  79. } // namespace descriptor_ops
  80. } // namespace detail
  81. } // namespace asio
  82. } // namespace boost
  83. #include <boost/asio/detail/pop_options.hpp>
  84. #if defined(BOOST_ASIO_HEADER_ONLY)
  85. # include <boost/asio/detail/impl/descriptor_ops.ipp>
  86. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  87. #endif // !defined(BOOST_ASIO_WINDOWS)
  88. // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  89. // && !defined(__CYGWIN__)
  90. #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP