descriptor_ops.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // detail/descriptor_ops.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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/cstdint.hpp>
  23. #include <boost/asio/detail/socket_types.hpp>
  24. #include <boost/asio/detail/push_options.hpp>
  25. namespace boost {
  26. namespace asio {
  27. namespace detail {
  28. namespace descriptor_ops {
  29. // Descriptor state bits.
  30. enum
  31. {
  32. // The user wants a non-blocking descriptor.
  33. user_set_non_blocking = 1,
  34. // The descriptor has been set non-blocking.
  35. internal_non_blocking = 2,
  36. // Helper "state" used to determine whether the descriptor is non-blocking.
  37. non_blocking = user_set_non_blocking | internal_non_blocking,
  38. // The descriptor may have been dup()-ed.
  39. possible_dup = 4
  40. };
  41. typedef unsigned char state_type;
  42. inline void get_last_error(
  43. boost::system::error_code& ec, bool is_error_condition)
  44. {
  45. if (!is_error_condition)
  46. {
  47. boost::asio::error::clear(ec);
  48. }
  49. else
  50. {
  51. ec = boost::system::error_code(errno,
  52. boost::asio::error::get_system_category());
  53. }
  54. }
  55. BOOST_ASIO_DECL int open(const char* path, int flags,
  56. boost::system::error_code& ec);
  57. BOOST_ASIO_DECL int open(const char* path, int flags, unsigned mode,
  58. boost::system::error_code& ec);
  59. BOOST_ASIO_DECL int close(int d, state_type& state,
  60. boost::system::error_code& ec);
  61. BOOST_ASIO_DECL bool set_user_non_blocking(int d,
  62. state_type& state, bool value, boost::system::error_code& ec);
  63. BOOST_ASIO_DECL bool set_internal_non_blocking(int d,
  64. state_type& state, bool value, boost::system::error_code& ec);
  65. typedef iovec buf;
  66. BOOST_ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs,
  67. std::size_t count, bool all_empty, boost::system::error_code& ec);
  68. BOOST_ASIO_DECL std::size_t sync_read1(int d, state_type state, void* data,
  69. std::size_t size, boost::system::error_code& ec);
  70. BOOST_ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count,
  71. boost::system::error_code& ec, std::size_t& bytes_transferred);
  72. BOOST_ASIO_DECL bool non_blocking_read1(int d, void* data, std::size_t size,
  73. boost::system::error_code& ec, std::size_t& bytes_transferred);
  74. BOOST_ASIO_DECL std::size_t sync_write(int d, state_type state,
  75. const buf* bufs, std::size_t count, bool all_empty,
  76. boost::system::error_code& ec);
  77. BOOST_ASIO_DECL std::size_t sync_write1(int d, state_type state,
  78. const void* data, std::size_t size, boost::system::error_code& ec);
  79. BOOST_ASIO_DECL bool non_blocking_write(int d,
  80. const buf* bufs, std::size_t count,
  81. boost::system::error_code& ec, std::size_t& bytes_transferred);
  82. BOOST_ASIO_DECL bool non_blocking_write1(int d,
  83. const void* data, std::size_t size,
  84. boost::system::error_code& ec, std::size_t& bytes_transferred);
  85. #if defined(BOOST_ASIO_HAS_FILE)
  86. BOOST_ASIO_DECL std::size_t sync_read_at(int d, state_type state,
  87. uint64_t offset, buf* bufs, std::size_t count, bool all_empty,
  88. boost::system::error_code& ec);
  89. BOOST_ASIO_DECL std::size_t sync_read_at1(int d, state_type state,
  90. uint64_t offset, void* data, std::size_t size,
  91. boost::system::error_code& ec);
  92. BOOST_ASIO_DECL bool non_blocking_read_at(int d, uint64_t offset,
  93. buf* bufs, std::size_t count, boost::system::error_code& ec,
  94. std::size_t& bytes_transferred);
  95. BOOST_ASIO_DECL bool non_blocking_read_at1(int d, uint64_t offset,
  96. void* data, std::size_t size, boost::system::error_code& ec,
  97. std::size_t& bytes_transferred);
  98. BOOST_ASIO_DECL std::size_t sync_write_at(int d, state_type state,
  99. uint64_t offset, const buf* bufs, std::size_t count, bool all_empty,
  100. boost::system::error_code& ec);
  101. BOOST_ASIO_DECL std::size_t sync_write_at1(int d, state_type state,
  102. uint64_t offset, const void* data, std::size_t size,
  103. boost::system::error_code& ec);
  104. BOOST_ASIO_DECL bool non_blocking_write_at(int d,
  105. uint64_t offset, const buf* bufs, std::size_t count,
  106. boost::system::error_code& ec, std::size_t& bytes_transferred);
  107. BOOST_ASIO_DECL bool non_blocking_write_at1(int d,
  108. uint64_t offset, const void* data, std::size_t size,
  109. boost::system::error_code& ec, std::size_t& bytes_transferred);
  110. #endif // defined(BOOST_ASIO_HAS_FILE)
  111. BOOST_ASIO_DECL int ioctl(int d, state_type& state, long cmd,
  112. ioctl_arg_type* arg, boost::system::error_code& ec);
  113. BOOST_ASIO_DECL int fcntl(int d, int cmd, boost::system::error_code& ec);
  114. BOOST_ASIO_DECL int fcntl(int d, int cmd,
  115. long arg, boost::system::error_code& ec);
  116. BOOST_ASIO_DECL int poll_read(int d,
  117. state_type state, boost::system::error_code& ec);
  118. BOOST_ASIO_DECL int poll_write(int d,
  119. state_type state, boost::system::error_code& ec);
  120. BOOST_ASIO_DECL int poll_error(int d,
  121. state_type state, boost::system::error_code& ec);
  122. } // namespace descriptor_ops
  123. } // namespace detail
  124. } // namespace asio
  125. } // namespace boost
  126. #include <boost/asio/detail/pop_options.hpp>
  127. #if defined(BOOST_ASIO_HEADER_ONLY)
  128. # include <boost/asio/detail/impl/descriptor_ops.ipp>
  129. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  130. #endif // !defined(BOOST_ASIO_WINDOWS)
  131. // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  132. // && !defined(__CYGWIN__)
  133. #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP