OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains types/constants and functions specific to data pipes. | 5 // This file contains types/constants and functions specific to data pipes. |
6 // | 6 // |
7 // Note: This header should be compilable as C. | 7 // Note: This header should be compilable as C. |
8 | 8 |
9 #ifndef MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ | 9 #ifndef MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ |
10 #define MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ | 10 #define MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // unframed, but must come as (multiples of) discrete elements, of the size | 128 // unframed, but must come as (multiples of) discrete elements, of the size |
129 // given in |options|. See |MojoCreateDataPipeOptions| for a description of the | 129 // given in |options|. See |MojoCreateDataPipeOptions| for a description of the |
130 // different options available for data pipes. | 130 // different options available for data pipes. |
131 // | 131 // |
132 // |options| may be set to null for a data pipe with the default options (which | 132 // |options| may be set to null for a data pipe with the default options (which |
133 // will have an element size of one byte and have some system-dependent | 133 // will have an element size of one byte and have some system-dependent |
134 // capacity). | 134 // capacity). |
135 // | 135 // |
136 // On success, |*data_pipe_producer_handle| will be set to the handle for the | 136 // On success, |*data_pipe_producer_handle| will be set to the handle for the |
137 // producer and |*data_pipe_consumer_handle| will be set to the handle for the | 137 // producer and |*data_pipe_consumer_handle| will be set to the handle for the |
138 // consumer. (On failure, they are not modified.) | 138 // consumer. (On failure, they are not modified.) The producer handle will have |
| 139 // (at least) the following rights: |MOJO_HANDLE_RIGHT_TRANSFER|, |
| 140 // |MOJO_HANDLE_RIGHT_WRITE|, |MOJO_HANDLE_RIGHT_GET_OPTIONS|, and |
| 141 // |MOJO_HANDLE_RIGHT_SET_OPTIONS|. The consumer handle will have (at least) the |
| 142 // following rights: |MOJO_HANDLE_RIGHT_TRANSFER|, |MOJO_HANDLE_RIGHT_READ|, |
| 143 // |MOJO_HANDLE_RIGHT_GET_OPTIONS|, and |MOJO_HANDLE_RIGHT_SET_OPTIONS| |
139 // | 144 // |
140 // Returns: | 145 // Returns: |
141 // |MOJO_RESULT_OK| on success. | 146 // |MOJO_RESULT_OK| on success. |
142 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 147 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
143 // |*options| is invalid). | 148 // |*options| is invalid). |
144 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | 149 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has |
145 // been reached (e.g., if the requested capacity was too large, or if the | 150 // been reached (e.g., if the requested capacity was too large, or if the |
146 // maximum number of handles was exceeded). | 151 // maximum number of handles was exceeded). |
147 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 152 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
148 MojoResult MojoCreateDataPipe( | 153 MojoResult MojoCreateDataPipe( |
149 const struct MojoCreateDataPipeOptions* MOJO_RESTRICT | 154 const struct MojoCreateDataPipeOptions* MOJO_RESTRICT |
150 options, // Optional in. | 155 options, // Optional in. |
151 MojoHandle* MOJO_RESTRICT data_pipe_producer_handle, // Out. | 156 MojoHandle* MOJO_RESTRICT data_pipe_producer_handle, // Out. |
152 MojoHandle* MOJO_RESTRICT data_pipe_consumer_handle); // Out. | 157 MojoHandle* MOJO_RESTRICT data_pipe_consumer_handle); // Out. |
153 | 158 |
154 // TODO(vtl): Probably should have a way of getting the | 159 // TODO(vtl): Probably should have a way of getting the |
155 // |MojoCreateDataPipeOptions| (maybe just rename it to |MojoDataPipeOptions|?) | 160 // |MojoCreateDataPipeOptions| (maybe just rename it to |MojoDataPipeOptions|?) |
156 // from either handle as well. | 161 // from either handle as well. |
157 | 162 |
158 // |MojoSetDataPipeProducerOptions()|: Sets options for the data pipe producer | 163 // |MojoSetDataPipeProducerOptions()|: Sets options for the data pipe producer |
159 // handle |data_pipe_producer_handle|. | 164 // handle |data_pipe_producer_handle| (which must have the |
| 165 // |MOJO_HANDLE_RIGHT_SET_OPTIONS| right). |
160 // | 166 // |
161 // |options| may be set to null to reset back to the default options. | 167 // |options| may be set to null to reset back to the default options. |
162 // | 168 // |
163 // Note that changing the write threshold may also result in the state (both | 169 // Note that changing the write threshold may also result in the state (both |
164 // satisfied or satisfiable) of the |MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD| handle | 170 // satisfied or satisfiable) of the |MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD| handle |
165 // signal being changed. | 171 // signal being changed. |
166 // | 172 // |
167 // Returns: | 173 // Returns: |
168 // |MOJO_RESULT_OK| on success. | 174 // |MOJO_RESULT_OK| on success. |
169 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 175 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
170 // |data_pipe_producer_handle| is not a valid data pipe producer handle or | 176 // |data_pipe_producer_handle| is not a valid data pipe producer handle or |
171 // |*options| is invalid). | 177 // |*options| is invalid). |
| 178 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_producer_handle| does not |
| 179 // have the |MOJO_HANDLE_RIGHT_SET_OPTIONS| right. |
172 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in | 180 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
173 // some transaction (that, e.g., may result in it being invalidated, such | 181 // some transaction (that, e.g., may result in it being invalidated, such |
174 // as being sent in a message). | 182 // as being sent in a message). |
175 MojoResult MojoSetDataPipeProducerOptions( | 183 MojoResult MojoSetDataPipeProducerOptions( |
176 MojoHandle data_pipe_producer_handle, // In. | 184 MojoHandle data_pipe_producer_handle, // In. |
177 const struct MojoDataPipeProducerOptions* options); // Optional in. | 185 const struct MojoDataPipeProducerOptions* options); // Optional in. |
178 | 186 |
179 // |MojoGetDataPipeProducerOptions()|: Gets options for the data pipe producer | 187 // |MojoGetDataPipeProducerOptions()|: Gets options for the data pipe producer |
180 // handle |data_pipe_producer_handle|. |options| should be non-null and point to | 188 // handle |data_pipe_producer_handle| (which must have the |
181 // a buffer of size |options_num_bytes|; |options_num_bytes| should be at least | 189 // |MOJO_HANDLE_RIGHT_GET_OPTIONS| right). |options| should be non-null and |
182 // 8 (the size of the first, and currently only, version of | 190 // point to a buffer of size |options_num_bytes|; |options_num_bytes| should be |
| 191 // at least 8 (the size of the first, and currently only, version of |
183 // |MojoDataPipeProducerOptions|). | 192 // |MojoDataPipeProducerOptions|). |
184 // | 193 // |
185 // On success, |*options| will be filled with information about the given | 194 // On success, |*options| will be filled with information about the given |
186 // buffer. Note that if additional (larger) versions of | 195 // buffer. Note that if additional (larger) versions of |
187 // |MojoDataPipeProducerOptions| are defined, the largest version permitted by | 196 // |MojoDataPipeProducerOptions| are defined, the largest version permitted by |
188 // |options_num_bytes| that is supported by the implementation will be filled. | 197 // |options_num_bytes| that is supported by the implementation will be filled. |
189 // Callers expecting more than the first 16-byte version must check the | 198 // Callers expecting more than the first 16-byte version must check the |
190 // resulting |options->struct_size|. | 199 // resulting |options->struct_size|. |
191 // | 200 // |
192 // Returns: | 201 // Returns: |
193 // |MOJO_RESULT_OK| on success. | 202 // |MOJO_RESULT_OK| on success. |
194 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 203 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
195 // |data_pipe_producer_handle| is not a valid data pipe producer handle, | 204 // |data_pipe_producer_handle| is not a valid data pipe producer handle, |
196 // |*options| is null, or |options_num_bytes| is too small). | 205 // |*options| is null, or |options_num_bytes| is too small). |
| 206 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_producer_handle| does not |
| 207 // have the |MOJO_HANDLE_RIGHT_GET_OPTIONS| right. |
197 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in | 208 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
198 // some transaction (that, e.g., may result in it being invalidated, such | 209 // some transaction (that, e.g., may result in it being invalidated, such |
199 // as being sent in a message). | 210 // as being sent in a message). |
200 MojoResult MojoGetDataPipeProducerOptions( | 211 MojoResult MojoGetDataPipeProducerOptions( |
201 MojoHandle data_pipe_producer_handle, // In. | 212 MojoHandle data_pipe_producer_handle, // In. |
202 struct MojoDataPipeProducerOptions* options, // Out. | 213 struct MojoDataPipeProducerOptions* options, // Out. |
203 uint32_t options_num_bytes); // In. | 214 uint32_t options_num_bytes); // In. |
204 | 215 |
205 // |MojoWriteData()|: Writes the given data to the data pipe producer given by | 216 // |MojoWriteData()|: Writes the given data to the data pipe producer given by |
206 // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|; | 217 // |data_pipe_producer_handle| (which must have the |MOJO_HANDLE_RIGHT_WRITE| |
207 // |*num_bytes| should be a multiple of the data pipe's element size. If | 218 // right). |elements| points to data of size |*num_bytes|; |*num_bytes| should |
| 219 // be a multiple of the data pipe's element size. If |
208 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data | 220 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data |
209 // will be written or none is. | 221 // will be written or none is. |
210 // | 222 // |
211 // On success, |*num_bytes| is set to the amount of data that was actually | 223 // On success, |*num_bytes| is set to the amount of data that was actually |
212 // written. | 224 // written. |
213 // | 225 // |
214 // Returns: | 226 // Returns: |
215 // |MOJO_RESULT_OK| on success. | 227 // |MOJO_RESULT_OK| on success. |
216 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 228 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
217 // |data_pipe_producer_dispatcher| is not a handle to a data pipe | 229 // |data_pipe_producer_handle| is not a handle to a data pipe producer or |
218 // producer or |*num_bytes| is not a multiple of the data pipe's element | 230 // |*num_bytes| is not a multiple of the data pipe's element size). |
219 // size). | 231 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_producer_handle| does not |
| 232 // have the |MOJO_HANDLE_RIGHT_WRITE| right. |
220 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been | 233 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been |
221 // closed. | 234 // closed. |
222 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has | 235 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |
223 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data | 236 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data |
224 // (specified by |*num_bytes|) could not be written. | 237 // (specified by |*num_bytes|) could not be written. |
225 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in | 238 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
226 // some transaction (that, e.g., may result in it being invalidated, such | 239 // some transaction (that, e.g., may result in it being invalidated, such |
227 // as being sent in a message), or if there is a two-phase write ongoing | 240 // as being sent in a message), or if there is a two-phase write ongoing |
228 // with |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been | 241 // with |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been |
229 // called, but not yet the matching |MojoEndWriteData()|). | 242 // called, but not yet the matching |MojoEndWriteData()|). |
230 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the | 243 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the |
231 // consumer is still open) and |flags| does *not* have | 244 // consumer is still open) and |flags| does *not* have |
232 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. | 245 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. |
233 // | 246 // |
234 // TODO(vtl): Should there be a way of querying how much data can be written? | 247 // TODO(vtl): Should there be a way of querying how much data can be written? |
235 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, // In. | 248 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, // In. |
236 const void* MOJO_RESTRICT elements, // In. | 249 const void* MOJO_RESTRICT elements, // In. |
237 uint32_t* MOJO_RESTRICT num_bytes, // In/out. | 250 uint32_t* MOJO_RESTRICT num_bytes, // In/out. |
238 MojoWriteDataFlags flags); // In. | 251 MojoWriteDataFlags flags); // In. |
239 | 252 |
240 // |MojoBeginWriteData()|: Begins a two-phase write to the data pipe producer | 253 // |MojoBeginWriteData()|: Begins a two-phase write to the data pipe producer |
241 // given by |data_pipe_producer_handle|. On success, |*buffer| will be a pointer | 254 // given by |data_pipe_producer_handle| (which must have the |
242 // to which the caller can write |*buffer_num_bytes| bytes of data. There are | 255 // |MOJO_HANDLE_RIGHT_WRITE| right). On success, |*buffer| will be a pointer to |
| 256 // which the caller can write |*buffer_num_bytes| bytes of data. There are |
243 // currently no flags allowed, so |flags| should be |MOJO_WRITE_DATA_FLAG_NONE|. | 257 // currently no flags allowed, so |flags| should be |MOJO_WRITE_DATA_FLAG_NONE|. |
244 // | 258 // |
245 // During a two-phase write, |data_pipe_producer_handle| is *not* writable. | 259 // During a two-phase write, |data_pipe_producer_handle| is *not* writable. |
246 // E.g., if another thread tries to write to it, it will get |MOJO_RESULT_BUSY|; | 260 // E.g., if another thread tries to write to it, it will get |MOJO_RESULT_BUSY|; |
247 // that thread can then wait for |data_pipe_producer_handle| to become writable | 261 // that thread can then wait for |data_pipe_producer_handle| to become writable |
248 // again. | 262 // again. |
249 // | 263 // |
250 // When |MojoBeginWriteData()| returns |MOJO_RESULT_OK|, and the caller has | 264 // When |MojoBeginWriteData()| returns |MOJO_RESULT_OK|, and the caller has |
251 // finished writing data to |*buffer|, it should call |MojoEndWriteData()| to | 265 // finished writing data to |*buffer|, it should call |MojoEndWriteData()| to |
252 // specify the amount written and to complete the two-phase write. | 266 // specify the amount written and to complete the two-phase write. |
253 // |MojoEndWriteData()| need not be called for other return values. | 267 // |MojoEndWriteData()| need not be called for other return values. |
254 // | 268 // |
255 // Returns: | 269 // Returns: |
256 // |MOJO_RESULT_OK| on success. | 270 // |MOJO_RESULT_OK| on success. |
257 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 271 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
258 // |data_pipe_producer_handle| is not a handle to a data pipe producer or | 272 // |data_pipe_producer_handle| is not a handle to a data pipe producer or |
259 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set). | 273 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set). |
| 274 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_producer_handle| does not |
| 275 // have the |MOJO_HANDLE_RIGHT_WRITE| right. |
260 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been | 276 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been |
261 // closed. | 277 // closed. |
262 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in | 278 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
263 // some transaction (that, e.g., may result in it being invalidated, such | 279 // some transaction (that, e.g., may result in it being invalidated, such |
264 // as being sent in a message), or if there is already a two-phase write | 280 // as being sent in a message), or if there is already a two-phase write |
265 // ongoing with |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| | 281 // ongoing with |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| |
266 // has been called, but not yet the matching |MojoEndWriteData()|). | 282 // has been called, but not yet the matching |MojoEndWriteData()|). |
267 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the | 283 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the |
268 // consumer is still open). | 284 // consumer is still open). |
269 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, // In. | 285 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, // In. |
270 void** MOJO_RESTRICT buffer, // Out. | 286 void** MOJO_RESTRICT buffer, // Out. |
271 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. | 287 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. |
272 MojoWriteDataFlags flags); // In. | 288 MojoWriteDataFlags flags); // In. |
273 | 289 |
274 // |MojoEndWriteData()|: Ends a two-phase write to the data pipe producer given | 290 // |MojoEndWriteData()|: Ends a two-phase write to the data pipe producer given |
275 // by |data_pipe_producer_handle| that was begun by a call to | 291 // by |data_pipe_producer_handle| (which must have the |MOJO_HANDLE_RIGHT_WRITE| |
276 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should | 292 // right) that was begun by a call to |MojoBeginWriteData()| on the same handle. |
277 // indicate the amount of data actually written; it must be less than or equal | 293 // |num_bytes_written| should indicate the amount of data actually written; it |
278 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must | 294 // must be less than or equal to the value of |*buffer_num_bytes| output by |
279 // be a multiple of the element size. The buffer given by |*buffer| from | 295 // |MojoBeginWriteData()| and must be a multiple of the element size. The buffer |
280 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written| | 296 // given by |*buffer| from |MojoBeginWriteData()| must have been filled with |
281 // bytes of data. | 297 // exactly |num_bytes_written| bytes of data. |
282 // | 298 // |
283 // On failure, the two-phase write (if any) is ended (so the handle may become | 299 // On failure, the two-phase write (if any) is ended (so the handle may become |
284 // writable again, if there's space available) but no data written to |*buffer| | 300 // writable again, if there's space available) but no data written to |*buffer| |
285 // is "put into" the data pipe. | 301 // is "put into" the data pipe. |
286 // | 302 // |
287 // Returns: | 303 // Returns: |
288 // |MOJO_RESULT_OK| on success. | 304 // |MOJO_RESULT_OK| on success. |
289 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 305 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
290 // |data_pipe_producer_handle| is not a handle to a data pipe producer or | 306 // |data_pipe_producer_handle| is not a handle to a data pipe producer or |
291 // |num_bytes_written| is invalid (greater than the maximum value provided | 307 // |num_bytes_written| is invalid (greater than the maximum value provided |
292 // by |MojoBeginWriteData()| or not a multiple of the element size). | 308 // by |MojoBeginWriteData()| or not a multiple of the element size). |
| 309 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_producer_handle| does not |
| 310 // have the |MOJO_HANDLE_RIGHT_WRITE| right. |
293 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a | 311 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a |
294 // two-phase write (e.g., |MojoBeginWriteData()| was not called or | 312 // two-phase write (e.g., |MojoBeginWriteData()| was not called or |
295 // |MojoEndWriteData()| has already been called). | 313 // |MojoEndWriteData()| has already been called). |
296 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in | 314 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
297 // some transaction (that, e.g., may result in it being invalidated, such | 315 // some transaction (that, e.g., may result in it being invalidated, such |
298 // as being sent in a message). | 316 // as being sent in a message). |
299 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, // In. | 317 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, // In. |
300 uint32_t num_bytes_written); // In. | 318 uint32_t num_bytes_written); // In. |
301 | 319 |
302 // |MojoSetDataPipeConsumerOptions()|: Sets options for the data pipe consumer | 320 // |MojoSetDataPipeConsumerOptions()|: Sets options for the data pipe consumer |
303 // handle |data_pipe_consumer_handle|. | 321 // handle |data_pipe_consumer_handle| (which must have the |
| 322 // |MOJO_HANDLE_RIGHT_SET_OPTIONS| right). |
304 // | 323 // |
305 // |options| may be set to null to reset back to the default options. | 324 // |options| may be set to null to reset back to the default options. |
306 // | 325 // |
307 // Note that changing the read threshold may also result in the state (both | 326 // Note that changing the read threshold may also result in the state (both |
308 // satisfied or satisfiable) of the |MOJO_HANDLE_SIGNAL_READ_THRESHOLD| handle | 327 // satisfied or satisfiable) of the |MOJO_HANDLE_SIGNAL_READ_THRESHOLD| handle |
309 // signal being changed. | 328 // signal being changed. |
310 // | 329 // |
311 // Returns: | 330 // Returns: |
312 // |MOJO_RESULT_OK| on success. | 331 // |MOJO_RESULT_OK| on success. |
313 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 332 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
314 // |data_pipe_consumer_handle| is not a valid data pipe consumer handle or | 333 // |data_pipe_consumer_handle| is not a valid data pipe consumer handle or |
315 // |*options| is invalid). | 334 // |*options| is invalid). |
| 335 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_consumer_handle| does not |
| 336 // have the |MOJO_HANDLE_RIGHT_SET_OPTIONS| right. |
316 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in | 337 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
317 // some transaction (that, e.g., may result in it being invalidated, such | 338 // some transaction (that, e.g., may result in it being invalidated, such |
318 // as being sent in a message). | 339 // as being sent in a message). |
319 MojoResult MojoSetDataPipeConsumerOptions( | 340 MojoResult MojoSetDataPipeConsumerOptions( |
320 MojoHandle data_pipe_consumer_handle, // In. | 341 MojoHandle data_pipe_consumer_handle, // In. |
321 const struct MojoDataPipeConsumerOptions* options); // Optional in. | 342 const struct MojoDataPipeConsumerOptions* options); // Optional in. |
322 | 343 |
323 // |MojoGetDataPipeConsumerOptions()|: Gets options for the data pipe consumer | 344 // |MojoGetDataPipeConsumerOptions()|: Gets options for the data pipe consumer |
324 // handle |data_pipe_consumer_handle|. |options| should be non-null and point to | 345 // handle |data_pipe_consumer_handle| (which must have the |
325 // a buffer of size |options_num_bytes|; |options_num_bytes| should be at least | 346 // |MOJO_HANDLE_RIGHT_GET_OPTIONS| right). |options| should be non-null and |
326 // 8 (the size of the first, and currently only, version of | 347 // point to a buffer of size |options_num_bytes|; |options_num_bytes| should be |
| 348 // at least 8 (the size of the first, and currently only, version of |
327 // |MojoDataPipeConsumerOptions|). | 349 // |MojoDataPipeConsumerOptions|). |
328 // | 350 // |
329 // On success, |*options| will be filled with information about the given | 351 // On success, |*options| will be filled with information about the given |
330 // buffer. Note that if additional (larger) versions of | 352 // buffer. Note that if additional (larger) versions of |
331 // |MojoDataPipeConsumerOptions| are defined, the largest version permitted by | 353 // |MojoDataPipeConsumerOptions| are defined, the largest version permitted by |
332 // |options_num_bytes| that is supported by the implementation will be filled. | 354 // |options_num_bytes| that is supported by the implementation will be filled. |
333 // Callers expecting more than the first 16-byte version must check the | 355 // Callers expecting more than the first 16-byte version must check the |
334 // resulting |options->struct_size|. | 356 // resulting |options->struct_size|. |
335 // | 357 // |
336 // Returns: | 358 // Returns: |
337 // |MOJO_RESULT_OK| on success. | 359 // |MOJO_RESULT_OK| on success. |
338 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 360 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
339 // |data_pipe_consumer_handle| is not a valid data pipe consumer handle, | 361 // |data_pipe_consumer_handle| is not a valid data pipe consumer handle, |
340 // |*options| is null, or |options_num_bytes| is too small). | 362 // |*options| is null, or |options_num_bytes| is too small). |
| 363 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_consumer_handle| does not |
| 364 // have the |MOJO_HANDLE_RIGHT_GET_OPTIONS| right. |
341 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in | 365 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
342 // some transaction (that, e.g., may result in it being invalidated, such | 366 // some transaction (that, e.g., may result in it being invalidated, such |
343 // as being sent in a message). | 367 // as being sent in a message). |
344 MojoResult MojoGetDataPipeConsumerOptions( | 368 MojoResult MojoGetDataPipeConsumerOptions( |
345 MojoHandle data_pipe_consumer_handle, // In. | 369 MojoHandle data_pipe_consumer_handle, // In. |
346 struct MojoDataPipeConsumerOptions* options, // Out. | 370 struct MojoDataPipeConsumerOptions* options, // Out. |
347 uint32_t options_num_bytes); // In. | 371 uint32_t options_num_bytes); // In. |
348 | 372 |
349 // |MojoReadData()|: Reads data from the data pipe consumer given by | 373 // |MojoReadData()|: Reads data from the data pipe consumer given by |
350 // |data_pipe_consumer_handle|. May also be used to discard data or query the | 374 // |data_pipe_consumer_handle| (which must have the |MOJO_HANDLE_RIGHT_READ| |
351 // amount of data available. | 375 // right). May also be used to discard data or query the amount of data |
| 376 // available. |
352 // | 377 // |
353 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor | 378 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor |
354 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which | 379 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which |
355 // must be a multiple of the data pipe's element size) bytes of data to | 380 // must be a multiple of the data pipe's element size) bytes of data to |
356 // |elements| and set |*num_bytes| to the amount actually read. If flags has | 381 // |elements| and set |*num_bytes| to the amount actually read. If flags has |
357 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly | 382 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly |
358 // |*num_bytes| bytes of data or none. Additionally, if flags has | 383 // |*num_bytes| bytes of data or none. Additionally, if flags has |
359 // |MOJO_READ_DATA_FLAG_PEEK| set, the data read will remain in the pipe and be | 384 // |MOJO_READ_DATA_FLAG_PEEK| set, the data read will remain in the pipe and be |
360 // available to future reads. | 385 // available to future reads. |
361 // | 386 // |
(...skipping 10 matching lines...) Expand all Loading... |
372 // case, |MOJO_READ_DATA_FLAG_DISCARD| must not be set, and | 397 // case, |MOJO_READ_DATA_FLAG_DISCARD| must not be set, and |
373 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is ignored, as are |elements| and the input | 398 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is ignored, as are |elements| and the input |
374 // value of |*num_bytes|. | 399 // value of |*num_bytes|. |
375 // | 400 // |
376 // Returns: | 401 // Returns: |
377 // |MOJO_RESULT_OK| on success (see above for a description of the different | 402 // |MOJO_RESULT_OK| on success (see above for a description of the different |
378 // operations). | 403 // operations). |
379 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 404 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
380 // |data_pipe_consumer_handle| is invalid, the combination of flags in | 405 // |data_pipe_consumer_handle| is invalid, the combination of flags in |
381 // |flags| is invalid, etc.). | 406 // |flags| is invalid, etc.). |
| 407 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_consumer_handle| does not |
| 408 // have the |MOJO_HANDLE_RIGHT_READ| right. |
382 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been | 409 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been |
383 // closed and data (or the required amount of data) was not available to | 410 // closed and data (or the required amount of data) was not available to |
384 // be read or discarded. | 411 // be read or discarded. |
385 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| | 412 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| |
386 // set and the required amount of data is not available to be read or | 413 // set and the required amount of data is not available to be read or |
387 // discarded (and the producer is still open). | 414 // discarded (and the producer is still open). |
388 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in | 415 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
389 // some transaction (that, e.g., may result in it being invalidated, such | 416 // some transaction (that, e.g., may result in it being invalidated, such |
390 // as being sent in a message), or if there is a two-phase read ongoing | 417 // as being sent in a message), or if there is a two-phase read ongoing |
391 // with |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been | 418 // with |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been |
392 // called, but not yet the matching |MojoEndReadData()|). | 419 // called, but not yet the matching |MojoEndReadData()|). |
393 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and | 420 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and |
394 // the producer is still open) and |flags| does *not* have | 421 // the producer is still open) and |flags| does *not* have |
395 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. | 422 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. |
396 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, // In. | 423 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, // In. |
397 void* MOJO_RESTRICT elements, // Out. | 424 void* MOJO_RESTRICT elements, // Out. |
398 uint32_t* MOJO_RESTRICT num_bytes, // In/out. | 425 uint32_t* MOJO_RESTRICT num_bytes, // In/out. |
399 MojoReadDataFlags flags); // In. | 426 MojoReadDataFlags flags); // In. |
400 | 427 |
401 // |MojoBeginReadData()|: Begins a two-phase read from the data pipe consumer | 428 // |MojoBeginReadData()|: Begins a two-phase read from the data pipe consumer |
402 // given by |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer | 429 // given by |data_pipe_consumer_handle| (which must have the |
403 // from which the caller can read |*buffer_num_bytes| bytes of data. There are | 430 // |MOJO_HANDLE_RIGHT_READ| right). On success, |*buffer| will be a pointer from |
| 431 // which the caller can read |*buffer_num_bytes| bytes of data. There are |
404 // currently no valid flags, so |flags| must be |MOJO_READ_DATA_FLAG_NONE|. | 432 // currently no valid flags, so |flags| must be |MOJO_READ_DATA_FLAG_NONE|. |
405 // | 433 // |
406 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable. | 434 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable. |
407 // E.g., if another thread tries to read from it, it will get | 435 // E.g., if another thread tries to read from it, it will get |
408 // |MOJO_RESULT_BUSY|; that thread can then wait for |data_pipe_consumer_handle| | 436 // |MOJO_RESULT_BUSY|; that thread can then wait for |data_pipe_consumer_handle| |
409 // to become readable again. | 437 // to become readable again. |
410 // | 438 // |
411 // Once the caller has finished reading data from |*buffer|, it should call | 439 // Once the caller has finished reading data from |*buffer|, it should call |
412 // |MojoEndReadData()| to specify the amount read and to complete the two-phase | 440 // |MojoEndReadData()| to specify the amount read and to complete the two-phase |
413 // read. | 441 // read. |
414 // | 442 // |
415 // Returns: | 443 // Returns: |
416 // |MOJO_RESULT_OK| on success. | 444 // |MOJO_RESULT_OK| on success. |
417 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 445 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
418 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer, | 446 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer, |
419 // or |flags| has invalid flags set). | 447 // or |flags| has invalid flags set). |
| 448 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_consumer_handle| does not |
| 449 // have the |MOJO_HANDLE_RIGHT_READ| right. |
420 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been | 450 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been |
421 // closed. | 451 // closed. |
422 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in | 452 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
423 // some transaction (that, e.g., may result in it being invalidated, such | 453 // some transaction (that, e.g., may result in it being invalidated, such |
424 // as being sent in a message), or if there is already a two-phase read | 454 // as being sent in a message), or if there is already a two-phase read |
425 // ongoing with |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| | 455 // ongoing with |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| |
426 // has been called, but not yet the matching |MojoEndReadData()|). | 456 // has been called, but not yet the matching |MojoEndReadData()|). |
427 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the | 457 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the |
428 // producer is still open). | 458 // producer is still open). |
429 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, // In. | 459 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, // In. |
430 const void** MOJO_RESTRICT buffer, // Out. | 460 const void** MOJO_RESTRICT buffer, // Out. |
431 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. | 461 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. |
432 MojoReadDataFlags flags); // In. | 462 MojoReadDataFlags flags); // In. |
433 | 463 |
434 // |MojoEndReadData()|: Ends a two-phase read from the data pipe consumer given | 464 // |MojoEndReadData()|: Ends a two-phase read from the data pipe consumer given |
435 // by |data_pipe_consumer_handle| that was begun by a call to | 465 // by |data_pipe_consumer_handle| (which must have the |MOJO_HANDLE_RIGHT_READ| |
436 // |MojoBeginReadData()| on the same handle. |num_bytes_read| should indicate | 466 // right) that was begun by a call to |MojoBeginReadData()| on the same handle. |
437 // the amount of data actually read; it must be less than or equal to the value | 467 // |num_bytes_read| should indicate the amount of data actually read; it must be |
438 // of |*buffer_num_bytes| output by |MojoBeginReadData()| and must be a multiple | 468 // less than or equal to the value of |*buffer_num_bytes| output by |
439 // of the element size. | 469 // |MojoBeginReadData()| and must be a multiple of the element size. |
440 // | 470 // |
441 // On failure, the two-phase read (if any) is ended (so the handle may become | 471 // On failure, the two-phase read (if any) is ended (so the handle may become |
442 // readable again) but no data is "removed" from the data pipe. | 472 // readable again) but no data is "removed" from the data pipe. |
443 // | 473 // |
444 // Returns: | 474 // Returns: |
445 // |MOJO_RESULT_OK| on success. | 475 // |MOJO_RESULT_OK| on success. |
446 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 476 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
447 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or | 477 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or |
448 // |num_bytes_written| is greater than the maximum value provided by | 478 // |num_bytes_written| is greater than the maximum value provided by |
449 // |MojoBeginReadData()| or not a multiple of the element size). | 479 // |MojoBeginReadData()| or not a multiple of the element size). |
| 480 // |MOJO_RESULT_PERMISSION_DENIED| if |data_pipe_consumer_handle| does not |
| 481 // have the |MOJO_HANDLE_RIGHT_READ| right. |
450 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a | 482 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a |
451 // two-phase read (e.g., |MojoBeginReadData()| was not called or | 483 // two-phase read (e.g., |MojoBeginReadData()| was not called or |
452 // |MojoEndReadData()| has already been called). | 484 // |MojoEndReadData()| has already been called). |
453 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in | 485 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
454 // some transaction (that, e.g., may result in it being invalidated, such | 486 // some transaction (that, e.g., may result in it being invalidated, such |
455 // as being sent in a message). | 487 // as being sent in a message). |
456 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, // In. | 488 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, // In. |
457 uint32_t num_bytes_read); // In. | 489 uint32_t num_bytes_read); // In. |
458 | 490 |
459 MOJO_END_EXTERN_C | 491 MOJO_END_EXTERN_C |
460 | 492 |
461 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ | 493 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ |
OLD | NEW |