1 //
2 // detail/descriptor_ops.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 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 
11 #ifndef BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP
12 #define BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include <boost/asio/detail/config.hpp>
19 
20 #if !defined(BOOST_ASIO_WINDOWS) \
21   && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
22   && !defined(__CYGWIN__)
23 
24 #include <cstddef>
25 #include <boost/asio/error.hpp>
26 #include <boost/system/error_code.hpp>
27 #include <boost/asio/detail/socket_types.hpp>
28 
29 #include <boost/asio/detail/push_options.hpp>
30 
31 namespace boost {
32 namespace asio {
33 namespace detail {
34 namespace descriptor_ops {
35 
36 // Descriptor state bits.
37 enum
38 {
39   // The user wants a non-blocking descriptor.
40   user_set_non_blocking = 1,
41 
42   // The descriptor has been set non-blocking.
43   internal_non_blocking = 2,
44 
45   // Helper "state" used to determine whether the descriptor is non-blocking.
46   non_blocking = user_set_non_blocking | internal_non_blocking,
47 
48   // The descriptor may have been dup()-ed.
49   possible_dup = 4
50 };
51 
52 typedef unsigned char state_type;
53 
54 template <typename ReturnType>
error_wrapper(ReturnType return_value,boost::system::error_code & ec)55 inline ReturnType error_wrapper(ReturnType return_value,
56     boost::system::error_code& ec)
57 {
58   ec = boost::system::error_code(errno,
59       boost::asio::error::get_system_category());
60   return return_value;
61 }
62 
63 BOOST_ASIO_DECL int open(const char* path, int flags,
64     boost::system::error_code& ec);
65 
66 BOOST_ASIO_DECL int close(int d, state_type& state,
67     boost::system::error_code& ec);
68 
69 BOOST_ASIO_DECL bool set_user_non_blocking(int d,
70     state_type& state, bool value, boost::system::error_code& ec);
71 
72 BOOST_ASIO_DECL bool set_internal_non_blocking(int d,
73     state_type& state, bool value, boost::system::error_code& ec);
74 
75 typedef iovec buf;
76 
77 BOOST_ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs,
78     std::size_t count, bool all_empty, boost::system::error_code& ec);
79 
80 BOOST_ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count,
81     boost::system::error_code& ec, std::size_t& bytes_transferred);
82 
83 BOOST_ASIO_DECL std::size_t sync_write(int d, state_type state,
84     const buf* bufs, std::size_t count, bool all_empty,
85     boost::system::error_code& ec);
86 
87 BOOST_ASIO_DECL bool non_blocking_write(int d,
88     const buf* bufs, std::size_t count,
89     boost::system::error_code& ec, std::size_t& bytes_transferred);
90 
91 BOOST_ASIO_DECL int ioctl(int d, state_type& state, long cmd,
92     ioctl_arg_type* arg, boost::system::error_code& ec);
93 
94 BOOST_ASIO_DECL int fcntl(int d, int cmd, boost::system::error_code& ec);
95 
96 BOOST_ASIO_DECL int fcntl(int d, int cmd,
97     long arg, boost::system::error_code& ec);
98 
99 BOOST_ASIO_DECL int poll_read(int d,
100     state_type state, boost::system::error_code& ec);
101 
102 BOOST_ASIO_DECL int poll_write(int d,
103     state_type state, boost::system::error_code& ec);
104 
105 BOOST_ASIO_DECL int poll_error(int d,
106     state_type state, boost::system::error_code& ec);
107 
108 } // namespace descriptor_ops
109 } // namespace detail
110 } // namespace asio
111 } // namespace boost
112 
113 #include <boost/asio/detail/pop_options.hpp>
114 
115 #if defined(BOOST_ASIO_HEADER_ONLY)
116 # include <boost/asio/detail/impl/descriptor_ops.ipp>
117 #endif // defined(BOOST_ASIO_HEADER_ONLY)
118 
119 #endif // !defined(BOOST_ASIO_WINDOWS)
120        //   && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
121        //   && !defined(__CYGWIN__)
122 
123 #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP
124