]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/process/async_pipe.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / process / async_pipe.hpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
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_PROCESS_ASYNC_PIPE_HPP
12 #define BOOST_PROCESS_ASYNC_PIPE_HPP
13
14 #include <boost/config.hpp>
15 #include <boost/process/detail/config.hpp>
16
17 #if defined(BOOST_POSIX_API)
18 #include <boost/process/detail/posix/async_pipe.hpp>
19 #elif defined(BOOST_WINDOWS_API)
20 #include <boost/process/detail/windows/async_pipe.hpp>
21 #endif
22
23 namespace boost { namespace process {
24
25
26 #if defined(BOOST_PROCESS_DOXYGEN)
27
28
29 /** Class implementing and asnychronous I/O-Object for use with boost.asio.
30 * It is based on the corresponding I/O Object, that is either boost::asio::windows::stream_handle or
31 * boost::asio::posix::stream_descriptor.
32 *
33 * It can be used directly with boost::asio::async_read or async_write.
34 *
35 * \note The object is copyable, but that does invoke a handle duplicate.
36 */
37 class async_pipe
38 {
39 public:
40 /** Typedef for the native handle representation.
41 * \note This is the handle on the system, not the boost.asio class.
42 *
43 */
44 typedef platform_specific native_handle_type;
45 /** Typedef for the handle representation of boost.asio.
46 *
47 */
48 typedef platform_specific handle_type;
49
50 /** Construct a new async_pipe, does automatically open the pipe.
51 * Initializes source and sink with the same io_context.
52 * @note Windows creates a named pipe here, where the name is automatically generated.
53 */
54 inline async_pipe(boost::asio::io_context & ios);
55
56 /** Construct a new async_pipe, does automatically open the pipe.
57 * @note Windows creates a named pipe here, where the name is automatically generated.
58 */
59 inline async_pipe(boost::asio::io_context & ios_source,
60 boost::asio::io_context & ios_sink);
61
62 /** Construct a new async_pipe, does automatically open.
63 * Initializes source and sink with the same io_context.
64 *
65 * @note Windows restricts possible names.
66 */
67 inline async_pipe(boost::asio::io_context & ios, const std::string & name);
68
69
70 /** Construct a new async_pipe, does automatically open.
71 *
72 * @note Windows restricts possible names.
73 */
74 inline async_pipe(boost::asio::io_context & ios_source,
75 boost::asio::io_context & ios_sink, const std::string & name);
76
77 /** Copy-Constructor of the async pipe.
78 * @note Windows requires a named pipe for this, if a the wrong type is used an exception is thrown.
79 *
80 */
81 async_pipe(const async_pipe& lhs);
82
83 /** Move-Constructor of the async pipe.
84 */
85 async_pipe(async_pipe&& lhs);
86
87 /** Construct the async-pipe from a pipe.
88 * @note Windows requires a named pipe for this, if a the wrong type is used an exception is thrown.
89 *
90 */
91 template<class CharT, class Traits = std::char_traits<CharT>>
92 explicit async_pipe(boost::asio::io_context & ios, const basic_pipe<CharT, Traits> & p);
93
94 /** Construct the async-pipe from a pipe, with two different io_context objects.
95 * @note Windows requires a named pipe for this, if a the wrong type is used an exception is thrown.
96 *
97 */
98 template<class CharT, class Traits = std::char_traits<CharT>>
99 explicit async_pipe(boost::asio::io_context & ios_source,
100 boost::asio::io_context & ios_sink,
101 const basic_pipe<CharT, Traits> & p);
102
103
104 /** Assign a basic_pipe.
105 * @note Windows requires a named pipe for this, if a the wrong type is used an exception is thrown.
106 *
107 */
108 template<class CharT, class Traits = std::char_traits<CharT>>
109 inline async_pipe& operator=(const basic_pipe<CharT, Traits>& p);
110
111 /** Copy Assign a pipe.
112 * @note Duplicates the handles.
113 */
114 async_pipe& operator=(const async_pipe& lhs);
115 /** Move assign a pipe */
116 async_pipe& operator=(async_pipe&& lhs);
117
118 /** Destructor. Closes the pipe handles. */
119 ~async_pipe();
120
121 /** Explicit cast to basic_pipe. */
122 template<class CharT, class Traits = std::char_traits<CharT>>
123 inline explicit operator basic_pipe<CharT, Traits>() const;
124
125 /** Cancel the current asynchronous operations. */
126 void cancel();
127 /** Close the pipe handles. */
128 void close();
129 /** Close the pipe handles. While passing an error_code
130 *
131 */
132 void close(std::error_code & ec);
133
134 /** Check if the pipes are open. */
135 bool is_open() const;
136
137 /** Async close, i.e. close after current operation is completed.
138 *
139 * \note There is no guarantee that this will indeed read the entire pipe-buffer
140 */
141 void async_close();
142
143 /** Read some data from the handle.
144
145 * See the boost.asio documentation for more details.
146 */
147 template<typename MutableBufferSequence>
148 std::size_t read_some(const MutableBufferSequence & buffers);
149
150 /** Write some data to the handle.
151
152 * See the boost.asio documentation for more details.
153 */
154 template<typename MutableBufferSequence>
155 std::size_t write_some(const MutableBufferSequence & buffers);
156
157 /** Get the native handle of the source. */
158 native_handle native_source() const {return const_cast<boost::asio::windows::stream_handle&>(_source).native();}
159 /** Get the native handle of the sink. */
160 native_handle native_sink () const {return const_cast<boost::asio::windows::stream_handle&>(_sink ).native();}
161
162 /** Start an asynchronous read.
163 *
164 * See the [boost.asio documentation](http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/reference/AsyncReadStream.html) for more details.
165 */
166 template<typename MutableBufferSequence,
167 typename ReadHandler>
168 detail::dummy async_read_some(
169 const MutableBufferSequence & buffers,
170 ReadHandler &&handler);
171
172 /** Start an asynchronous write.
173
174 * See the [boost.asio documentation](http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/reference/AsyncWriteStream.html) for more details.
175 */
176 template<typename ConstBufferSequence,
177 typename WriteHandler>
178 detail::dummy async_write_some(
179 const ConstBufferSequence & buffers,
180 WriteHandler && handler);
181
182 ///Get the asio handle of the pipe sink.
183 const handle_type & sink () const &;
184 ///Get the asio handle of the pipe source.
185 const handle_type & source() const &;
186
187 ///Get the asio handle of the pipe sink. Qualified as rvalue
188 handle_type && sink () &&;
189 ///Get the asio handle of the pipe source. Qualified as rvalue
190 handle_type && source() &&;
191
192 /// Move the source out of this class and change the io_context. Qualified as rvalue. \attention Will always move.
193 handle_type source(::boost::asio::io_context& ios) &&;
194 /// Move the sink out of this class and change the io_context. Qualified as rvalue. \attention Will always move
195 handle_type sink (::boost::asio::io_context& ios) &&;
196
197 /// Copy the source out of this class and change the io_context. \attention Will always copy.
198 handle_type source(::boost::asio::io_context& ios) const &;
199 /// Copy the sink out of this class and change the io_context. \attention Will always copy
200 handle_type sink (::boost::asio::io_context& ios) const &;
201
202
203
204 };
205
206 #else
207 using ::boost::process::detail::api::async_pipe;
208 #endif
209
210
211 }}
212
213
214
215 #endif