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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // |MojoBeginReadData()|. | 76 // |MojoBeginReadData()|. |
77 // |MOJO_READ_DATA_FLAG_NONE| - No flags; default mode. | 77 // |MOJO_READ_DATA_FLAG_NONE| - No flags; default mode. |
78 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| - Read (or discard) either the requested | 78 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| - Read (or discard) either the requested |
79 // number of elements or none. | 79 // number of elements or none. |
80 // |MOJO_READ_DATA_FLAG_DISCARD| - Discard (up to) the requested number of | 80 // |MOJO_READ_DATA_FLAG_DISCARD| - Discard (up to) the requested number of |
81 // elements. | 81 // elements. |
82 // |MOJO_READ_DATA_FLAG_QUERY| - Query the number of elements available to | 82 // |MOJO_READ_DATA_FLAG_QUERY| - Query the number of elements available to |
83 // read. For use with |MojoReadData()| only. Mutually exclusive with | 83 // read. For use with |MojoReadData()| only. Mutually exclusive with |
84 // |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is | 84 // |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is |
85 // ignored if this flag is set. | 85 // ignored if this flag is set. |
| 86 // |MOJO_READ_DATA_FLAG_PEEK| - Read elements without removing them. For use |
| 87 // with |MojoReadData()| only. Mutually exclusive with |
| 88 // |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_QUERY|. |
86 | 89 |
87 typedef uint32_t MojoReadDataFlags; | 90 typedef uint32_t MojoReadDataFlags; |
88 | 91 |
89 #ifdef __cplusplus | 92 #ifdef __cplusplus |
90 const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE = 0; | 93 const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE = 0; |
91 const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0; | 94 const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0; |
92 const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1; | 95 const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1; |
93 const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2; | 96 const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2; |
| 97 const MojoReadDataFlags MOJO_READ_DATA_FLAG_PEEK = 1 << 3; |
94 #else | 98 #else |
95 #define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags)0) | 99 #define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags)0) |
96 #define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags)1 << 0) | 100 #define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags)1 << 0) |
97 #define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags)1 << 1) | 101 #define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags)1 << 1) |
98 #define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags)1 << 2) | 102 #define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags)1 << 2) |
| 103 #define MOJO_READ_DATA_FLAG_PEEK ((MojoReadDataFlags)1 << 3) |
99 #endif | 104 #endif |
100 | 105 |
101 #ifdef __cplusplus | 106 #ifdef __cplusplus |
102 extern "C" { | 107 extern "C" { |
103 #endif | 108 #endif |
104 | 109 |
105 // Note: See the comment in functions.h about the meaning of the "optional" | 110 // Note: See the comment in functions.h about the meaning of the "optional" |
106 // label for pointer parameters. | 111 // label for pointer parameters. |
107 | 112 |
108 // Creates a data pipe, which is a unidirectional communication channel for | 113 // Creates a data pipe, which is a unidirectional communication channel for |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 uint32_t num_bytes_written); | 252 uint32_t num_bytes_written); |
248 | 253 |
249 // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|. | 254 // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|. |
250 // May also be used to discard data or query the amount of data available. | 255 // May also be used to discard data or query the amount of data available. |
251 // | 256 // |
252 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor | 257 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor |
253 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which | 258 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which |
254 // must be a multiple of the data pipe's element size) bytes of data to | 259 // must be a multiple of the data pipe's element size) bytes of data to |
255 // |elements| and set |*num_bytes| to the amount actually read. If flags has | 260 // |elements| and set |*num_bytes| to the amount actually read. If flags has |
256 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly | 261 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly |
257 // |*num_bytes| bytes of data or none. | 262 // |*num_bytes| bytes of data or none. Additionally, if flags has |
| 263 // |MOJO_READ_DATA_FLAG_PEEK| set, the data read will remain in the pipe and be |
| 264 // available to future reads. |
258 // | 265 // |
259 // If flags has |MOJO_READ_DATA_FLAG_DISCARD| set, it discards up to | 266 // If flags has |MOJO_READ_DATA_FLAG_DISCARD| set, it discards up to |
260 // |*num_bytes| (which again be a multiple of the element size) bytes of data, | 267 // |*num_bytes| (which again be a multiple of the element size) bytes of data, |
261 // setting |*num_bytes| to the amount actually discarded. If flags has | 268 // setting |*num_bytes| to the amount actually discarded. If flags has |
262 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE|, it will either discard exactly | 269 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE|, it will either discard exactly |
263 // |*num_bytes| bytes of data or none. In this case, |MOJO_READ_DATA_FLAG_QUERY| | 270 // |*num_bytes| bytes of data or none. In this case, |MOJO_READ_DATA_FLAG_QUERY| |
264 // must not be set, and |elements| is ignored (and should typically be set to | 271 // must not be set, and |elements| is ignored (and should typically be set to |
265 // null). | 272 // null). |
266 // | 273 // |
267 // If flags has |MOJO_READ_DATA_FLAG_QUERY| set, it queries the amount of data | 274 // If flags has |MOJO_READ_DATA_FLAG_QUERY| set, it queries the amount of data |
(...skipping 25 matching lines...) Expand all Loading... |
293 uint32_t* num_bytes, // In/out. | 300 uint32_t* num_bytes, // In/out. |
294 MojoReadDataFlags flags); | 301 MojoReadDataFlags flags); |
295 | 302 |
296 // Begins a two-phase read from the data pipe consumer given by | 303 // Begins a two-phase read from the data pipe consumer given by |
297 // |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from | 304 // |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from |
298 // which the caller can read |*buffer_num_bytes| bytes of data. If flags has | 305 // which the caller can read |*buffer_num_bytes| bytes of data. If flags has |
299 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, then the output value | 306 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, then the output value |
300 // |*buffer_num_bytes| will be at least as large as its input value, which must | 307 // |*buffer_num_bytes| will be at least as large as its input value, which must |
301 // also be a multiple of the element size (if |MOJO_READ_DATA_FLAG_ALL_OR_NONE| | 308 // also be a multiple of the element size (if |MOJO_READ_DATA_FLAG_ALL_OR_NONE| |
302 // is not set, the input value of |*buffer_num_bytes| is ignored). |flags| must | 309 // is not set, the input value of |*buffer_num_bytes| is ignored). |flags| must |
303 // not have |MOJO_READ_DATA_FLAG_DISCARD| or |MOJO_READ_DATA_FLAG_QUERY| set. | 310 // not have |MOJO_READ_DATA_FLAG_DISCARD|, |MOJO_READ_DATA_FLAG_QUERY|, or |
| 311 // |MOJO_READ_DATA_FLAG_PEEK| set. |
304 // | 312 // |
305 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable. | 313 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable. |
306 // E.g., if another thread tries to read from it, it will get | 314 // E.g., if another thread tries to read from it, it will get |
307 // |MOJO_RESULT_BUSY|; that thread can then wait for |data_pipe_consumer_handle| | 315 // |MOJO_RESULT_BUSY|; that thread can then wait for |data_pipe_consumer_handle| |
308 // to become readable again. | 316 // to become readable again. |
309 // | 317 // |
310 // Once the caller has finished reading data from |*buffer|, it should call | 318 // Once the caller has finished reading data from |*buffer|, it should call |
311 // |MojoEndReadData()| to specify the amount read and to complete the two-phase | 319 // |MojoEndReadData()| to specify the amount read and to complete the two-phase |
312 // read. | 320 // read. |
313 // | 321 // |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 // |MojoEndReadData()| has already been called). | 364 // |MojoEndReadData()| has already been called). |
357 MOJO_SYSTEM_EXPORT MojoResult | 365 MOJO_SYSTEM_EXPORT MojoResult |
358 MojoEndReadData(MojoHandle data_pipe_consumer_handle, | 366 MojoEndReadData(MojoHandle data_pipe_consumer_handle, |
359 uint32_t num_bytes_read); | 367 uint32_t num_bytes_read); |
360 | 368 |
361 #ifdef __cplusplus | 369 #ifdef __cplusplus |
362 } // extern "C" | 370 } // extern "C" |
363 #endif | 371 #endif |
364 | 372 |
365 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ | 373 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ |
OLD | NEW |