descriptor_ops.hpp 2.8 KB

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