1 //
2 // detail/descriptor_ops.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 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 
get_last_error(boost::system::error_code & ec,bool is_error_condition)54 inline void get_last_error(
55     boost::system::error_code& ec, bool is_error_condition)
56 {
57   if (!is_error_condition)
58   {
59     ec.assign(0, ec.category());
60   }
61   else
62   {
63     ec = boost::system::error_code(errno,
64         boost::asio::error::get_system_category());
65   }
66 }
67 
68 BOOST_ASIO_DECL int open(const char* path, int flags,
69     boost::system::error_code& ec);
70 
71 BOOST_ASIO_DECL int close(int d, state_type& state,
72     boost::system::error_code& ec);
73 
74 BOOST_ASIO_DECL bool set_user_non_blocking(int d,
75     state_type& state, bool value, boost::system::error_code& ec);
76 
77 BOOST_ASIO_DECL bool set_internal_non_blocking(int d,
78     state_type& state, bool value, boost::system::error_code& ec);
79 
80 typedef iovec buf;
81 
82 BOOST_ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs,
83     std::size_t count, bool all_empty, boost::system::error_code& ec);
84 
85 BOOST_ASIO_DECL std::size_t sync_read1(int d, state_type state, void* data,
86     std::size_t size, boost::system::error_code& ec);
87 
88 BOOST_ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count,
89     boost::system::error_code& ec, std::size_t& bytes_transferred);
90 
91 BOOST_ASIO_DECL bool non_blocking_read1(int d, void* data, std::size_t size,
92     boost::system::error_code& ec, std::size_t& bytes_transferred);
93 
94 BOOST_ASIO_DECL std::size_t sync_write(int d, state_type state,
95     const buf* bufs, std::size_t count, bool all_empty,
96     boost::system::error_code& ec);
97 
98 BOOST_ASIO_DECL std::size_t sync_write1(int d, state_type state,
99     const void* data, std::size_t size, boost::system::error_code& ec);
100 
101 BOOST_ASIO_DECL bool non_blocking_write(int d,
102     const buf* bufs, std::size_t count,
103     boost::system::error_code& ec, std::size_t& bytes_transferred);
104 
105 BOOST_ASIO_DECL bool non_blocking_write1(int d,
106     const void* data, std::size_t size,
107     boost::system::error_code& ec, std::size_t& bytes_transferred);
108 
109 BOOST_ASIO_DECL int ioctl(int d, state_type& state, long cmd,
110     ioctl_arg_type* arg, boost::system::error_code& ec);
111 
112 BOOST_ASIO_DECL int fcntl(int d, int cmd, boost::system::error_code& ec);
113 
114 BOOST_ASIO_DECL int fcntl(int d, int cmd,
115     long arg, boost::system::error_code& ec);
116 
117 BOOST_ASIO_DECL int poll_read(int d,
118     state_type state, boost::system::error_code& ec);
119 
120 BOOST_ASIO_DECL int poll_write(int d,
121     state_type state, boost::system::error_code& ec);
122 
123 BOOST_ASIO_DECL int poll_error(int d,
124     state_type state, boost::system::error_code& ec);
125 
126 } // namespace descriptor_ops
127 } // namespace detail
128 } // namespace asio
129 } // namespace boost
130 
131 #include <boost/asio/detail/pop_options.hpp>
132 
133 #if defined(BOOST_ASIO_HEADER_ONLY)
134 # include <boost/asio/detail/impl/descriptor_ops.ipp>
135 #endif // defined(BOOST_ASIO_HEADER_ONLY)
136 
137 #endif // !defined(BOOST_ASIO_WINDOWS)
138        //   && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
139        //   && !defined(__CYGWIN__)
140 
141 #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP
142