descriptor_ops.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // detail/descriptor_ops.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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. inline void get_last_error(
  42. boost::system::error_code& ec, bool is_error_condition)
  43. {
  44. if (!is_error_condition)
  45. {
  46. ec.assign(0, ec.category());
  47. }
  48. else
  49. {
  50. ec = boost::system::error_code(errno,
  51. boost::asio::error::get_system_category());
  52. }
  53. }
  54. BOOST_ASIO_DECL int open(const char* path, int flags,
  55. boost::system::error_code& ec);
  56. BOOST_ASIO_DECL int close(int d, state_type& state,
  57. boost::system::error_code& ec);
  58. BOOST_ASIO_DECL bool set_user_non_blocking(int d,
  59. state_type& state, bool value, boost::system::error_code& ec);
  60. BOOST_ASIO_DECL bool set_internal_non_blocking(int d,
  61. state_type& state, bool value, boost::system::error_code& ec);
  62. typedef iovec buf;
  63. BOOST_ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs,
  64. std::size_t count, bool all_empty, boost::system::error_code& ec);
  65. BOOST_ASIO_DECL std::size_t sync_read1(int d, state_type state, void* data,
  66. std::size_t size, boost::system::error_code& ec);
  67. BOOST_ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count,
  68. boost::system::error_code& ec, std::size_t& bytes_transferred);
  69. BOOST_ASIO_DECL bool non_blocking_read1(int d, void* data, std::size_t size,
  70. boost::system::error_code& ec, std::size_t& bytes_transferred);
  71. BOOST_ASIO_DECL std::size_t sync_write(int d, state_type state,
  72. const buf* bufs, std::size_t count, bool all_empty,
  73. boost::system::error_code& ec);
  74. BOOST_ASIO_DECL std::size_t sync_write1(int d, state_type state,
  75. const void* data, std::size_t size, boost::system::error_code& ec);
  76. BOOST_ASIO_DECL bool non_blocking_write(int d,
  77. const buf* bufs, std::size_t count,
  78. boost::system::error_code& ec, std::size_t& bytes_transferred);
  79. BOOST_ASIO_DECL bool non_blocking_write1(int d,
  80. const void* data, std::size_t size,
  81. boost::system::error_code& ec, std::size_t& bytes_transferred);
  82. BOOST_ASIO_DECL int ioctl(int d, state_type& state, long cmd,
  83. ioctl_arg_type* arg, boost::system::error_code& ec);
  84. BOOST_ASIO_DECL int fcntl(int d, int cmd, boost::system::error_code& ec);
  85. BOOST_ASIO_DECL int fcntl(int d, int cmd,
  86. long arg, boost::system::error_code& ec);
  87. BOOST_ASIO_DECL int poll_read(int d,
  88. state_type state, boost::system::error_code& ec);
  89. BOOST_ASIO_DECL int poll_write(int d,
  90. state_type state, boost::system::error_code& ec);
  91. BOOST_ASIO_DECL int poll_error(int d,
  92. state_type state, boost::system::error_code& ec);
  93. } // namespace descriptor_ops
  94. } // namespace detail
  95. } // namespace asio
  96. } // namespace boost
  97. #include <boost/asio/detail/pop_options.hpp>
  98. #if defined(BOOST_ASIO_HEADER_ONLY)
  99. # include <boost/asio/detail/impl/descriptor_ops.ipp>
  100. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  101. #endif // !defined(BOOST_ASIO_WINDOWS)
  102. // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  103. // && !defined(__CYGWIN__)
  104. #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP