descriptor_ops.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // detail/descriptor_ops.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_DETAIL_DESCRIPTOR_OPS_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #if !defined(ASIO_WINDOWS) \
  17. && !defined(ASIO_WINDOWS_RUNTIME) \
  18. && !defined(__CYGWIN__)
  19. #include <cstddef>
  20. #include "asio/error.hpp"
  21. #include "asio/error_code.hpp"
  22. #include "asio/detail/cstdint.hpp"
  23. #include "asio/detail/socket_types.hpp"
  24. #include "asio/detail/push_options.hpp"
  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. asio::error_code& ec, bool is_error_condition)
  43. {
  44. if (!is_error_condition)
  45. {
  46. asio::error::clear(ec);
  47. }
  48. else
  49. {
  50. ec = asio::error_code(errno,
  51. asio::error::get_system_category());
  52. }
  53. }
  54. ASIO_DECL int open(const char* path, int flags,
  55. asio::error_code& ec);
  56. ASIO_DECL int open(const char* path, int flags, unsigned mode,
  57. asio::error_code& ec);
  58. ASIO_DECL int close(int d, state_type& state,
  59. asio::error_code& ec);
  60. ASIO_DECL bool set_user_non_blocking(int d,
  61. state_type& state, bool value, asio::error_code& ec);
  62. ASIO_DECL bool set_internal_non_blocking(int d,
  63. state_type& state, bool value, asio::error_code& ec);
  64. typedef iovec buf;
  65. ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs,
  66. std::size_t count, bool all_empty, asio::error_code& ec);
  67. ASIO_DECL std::size_t sync_read1(int d, state_type state, void* data,
  68. std::size_t size, asio::error_code& ec);
  69. ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count,
  70. asio::error_code& ec, std::size_t& bytes_transferred);
  71. ASIO_DECL bool non_blocking_read1(int d, void* data, std::size_t size,
  72. asio::error_code& ec, std::size_t& bytes_transferred);
  73. ASIO_DECL std::size_t sync_write(int d, state_type state,
  74. const buf* bufs, std::size_t count, bool all_empty,
  75. asio::error_code& ec);
  76. ASIO_DECL std::size_t sync_write1(int d, state_type state,
  77. const void* data, std::size_t size, asio::error_code& ec);
  78. ASIO_DECL bool non_blocking_write(int d,
  79. const buf* bufs, std::size_t count,
  80. asio::error_code& ec, std::size_t& bytes_transferred);
  81. ASIO_DECL bool non_blocking_write1(int d,
  82. const void* data, std::size_t size,
  83. asio::error_code& ec, std::size_t& bytes_transferred);
  84. #if defined(ASIO_HAS_FILE)
  85. ASIO_DECL std::size_t sync_read_at(int d, state_type state,
  86. uint64_t offset, buf* bufs, std::size_t count, bool all_empty,
  87. asio::error_code& ec);
  88. ASIO_DECL std::size_t sync_read_at1(int d, state_type state,
  89. uint64_t offset, void* data, std::size_t size,
  90. asio::error_code& ec);
  91. ASIO_DECL bool non_blocking_read_at(int d, uint64_t offset,
  92. buf* bufs, std::size_t count, asio::error_code& ec,
  93. std::size_t& bytes_transferred);
  94. ASIO_DECL bool non_blocking_read_at1(int d, uint64_t offset,
  95. void* data, std::size_t size, asio::error_code& ec,
  96. std::size_t& bytes_transferred);
  97. ASIO_DECL std::size_t sync_write_at(int d, state_type state,
  98. uint64_t offset, const buf* bufs, std::size_t count, bool all_empty,
  99. asio::error_code& ec);
  100. ASIO_DECL std::size_t sync_write_at1(int d, state_type state,
  101. uint64_t offset, const void* data, std::size_t size,
  102. asio::error_code& ec);
  103. ASIO_DECL bool non_blocking_write_at(int d,
  104. uint64_t offset, const buf* bufs, std::size_t count,
  105. asio::error_code& ec, std::size_t& bytes_transferred);
  106. ASIO_DECL bool non_blocking_write_at1(int d,
  107. uint64_t offset, const void* data, std::size_t size,
  108. asio::error_code& ec, std::size_t& bytes_transferred);
  109. #endif // defined(ASIO_HAS_FILE)
  110. ASIO_DECL int ioctl(int d, state_type& state, long cmd,
  111. ioctl_arg_type* arg, asio::error_code& ec);
  112. ASIO_DECL int fcntl(int d, int cmd, asio::error_code& ec);
  113. ASIO_DECL int fcntl(int d, int cmd,
  114. long arg, asio::error_code& ec);
  115. ASIO_DECL int poll_read(int d,
  116. state_type state, asio::error_code& ec);
  117. ASIO_DECL int poll_write(int d,
  118. state_type state, asio::error_code& ec);
  119. ASIO_DECL int poll_error(int d,
  120. state_type state, asio::error_code& ec);
  121. } // namespace descriptor_ops
  122. } // namespace detail
  123. } // namespace asio
  124. #include "asio/detail/pop_options.hpp"
  125. #if defined(ASIO_HEADER_ONLY)
  126. # include "asio/detail/impl/descriptor_ops.ipp"
  127. #endif // defined(ASIO_HEADER_ONLY)
  128. #endif // !defined(ASIO_WINDOWS)
  129. // && !defined(ASIO_WINDOWS_RUNTIME)
  130. // && !defined(__CYGWIN__)
  131. #endif // ASIO_DETAIL_DESCRIPTOR_OPS_HPP