descriptor_ops.hpp 3.4 KB

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