Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: mojo/public/c/system/data_pipe.h

Issue 2783223004: Adds lots of Mojo documentation (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_
11 11
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 #include "mojo/public/c/system/macros.h" 14 #include "mojo/public/c/system/macros.h"
15 #include "mojo/public/c/system/system_export.h" 15 #include "mojo/public/c/system/system_export.h"
16 #include "mojo/public/c/system/types.h" 16 #include "mojo/public/c/system/types.h"
17 17
18 // |MojoCreateDataPipeOptions|: Used to specify creation parameters for a data 18 // |MojoCreateDataPipeOptions|: Used to specify creation parameters for a data
19 // pipe to |MojoCreateDataPipe()|. 19 // pipe to |MojoCreateDataPipe()|.
20 //
20 // |uint32_t struct_size|: Set to the size of the |MojoCreateDataPipeOptions| 21 // |uint32_t struct_size|: Set to the size of the |MojoCreateDataPipeOptions|
21 // struct. (Used to allow for future extensions.) 22 // struct. (Used to allow for future extensions.)
23 //
22 // |MojoCreateDataPipeOptionsFlags flags|: Used to specify different modes of 24 // |MojoCreateDataPipeOptionsFlags flags|: Used to specify different modes of
23 // operation. 25 // operation. May be some combination of the following values:
24 // |MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE|: No flags; default mode. 26 //
27 // |MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE|: No flags; default mode.
28 //
25 // |uint32_t element_num_bytes|: The size of an element, in bytes. All 29 // |uint32_t element_num_bytes|: The size of an element, in bytes. All
26 // transactions and buffers will consist of an integral number of 30 // transactions and buffers will consist of an integral number of
27 // elements. Must be nonzero. 31 // elements. Must be nonzero.
32 //
28 // |uint32_t capacity_num_bytes|: The capacity of the data pipe, in number of 33 // |uint32_t capacity_num_bytes|: The capacity of the data pipe, in number of
29 // bytes; must be a multiple of |element_num_bytes|. The data pipe will 34 // bytes; must be a multiple of |element_num_bytes|. The data pipe will
30 // always be able to queue AT LEAST this much data. Set to zero to opt for 35 // always be able to queue AT LEAST this much data. Set to zero to opt for
31 // a system-dependent automatically-calculated capacity (which will always 36 // a system-dependent automatically-calculated capacity (which will always
32 // be at least one element). 37 // be at least one element).
33 38
34 typedef uint32_t MojoCreateDataPipeOptionsFlags; 39 typedef uint32_t MojoCreateDataPipeOptionsFlags;
35 40
36 #ifdef __cplusplus 41 #ifdef __cplusplus
37 const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE = 42 const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE =
38 0; 43 0;
39 #else 44 #else
40 #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE \ 45 #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE \
41 ((MojoCreateDataPipeOptionsFlags)0) 46 ((MojoCreateDataPipeOptionsFlags)0)
42 #endif 47 #endif
43 48
44 MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment"); 49 MOJO_STATIC_ASSERT(MOJO_ALIGNOF(int64_t) == 8, "int64_t has weird alignment");
45 struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions { 50 struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions {
46 MOJO_ALIGNAS(4) uint32_t struct_size; 51 MOJO_ALIGNAS(4) uint32_t struct_size;
47 MOJO_ALIGNAS(4) MojoCreateDataPipeOptionsFlags flags; 52 MOJO_ALIGNAS(4) MojoCreateDataPipeOptionsFlags flags;
48 MOJO_ALIGNAS(4) uint32_t element_num_bytes; 53 MOJO_ALIGNAS(4) uint32_t element_num_bytes;
49 MOJO_ALIGNAS(4) uint32_t capacity_num_bytes; 54 MOJO_ALIGNAS(4) uint32_t capacity_num_bytes;
50 }; 55 };
51 MOJO_STATIC_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16, 56 MOJO_STATIC_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16,
52 "MojoCreateDataPipeOptions has wrong size"); 57 "MojoCreateDataPipeOptions has wrong size");
53 58
54 // |MojoWriteDataFlags|: Used to specify different modes to |MojoWriteData()| 59 // |MojoWriteDataFlags|: Used to specify different modes to |MojoWriteData()|
55 // and |MojoBeginWriteData()|. 60 // and |MojoBeginWriteData()|. May be some combination of the following values:
61 //
56 // |MOJO_WRITE_DATA_FLAG_NONE| - No flags; default mode. 62 // |MOJO_WRITE_DATA_FLAG_NONE| - No flags; default mode.
57 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| - Write either all the elements 63 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| - Write either all the elements
58 // requested or none of them. 64 // requested or none of them.
59 65
60 typedef uint32_t MojoWriteDataFlags; 66 typedef uint32_t MojoWriteDataFlags;
61 67
62 #ifdef __cplusplus 68 #ifdef __cplusplus
63 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE = 0; 69 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE = 0;
64 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0; 70 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0;
65 #else 71 #else
66 #define MOJO_WRITE_DATA_FLAG_NONE ((MojoWriteDataFlags)0) 72 #define MOJO_WRITE_DATA_FLAG_NONE ((MojoWriteDataFlags)0)
67 #define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((MojoWriteDataFlags)1 << 0) 73 #define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((MojoWriteDataFlags)1 << 0)
68 #endif 74 #endif
69 75
70 // |MojoReadDataFlags|: Used to specify different modes to |MojoReadData()| and 76 // |MojoReadDataFlags|: Used to specify different modes to |MojoReadData()| and
71 // |MojoBeginReadData()|. 77 // |MojoBeginReadData()|. May be some combination of the following values:
78 //
72 // |MOJO_READ_DATA_FLAG_NONE| - No flags; default mode. 79 // |MOJO_READ_DATA_FLAG_NONE| - No flags; default mode.
73 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| - Read (or discard) either the requested 80 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| - Read (or discard) either the requested
74 // number of elements or none. 81 // number of elements or none. NOTE: This flag is not currently supported
82 // by |MojoBeginReadData()|.
75 // |MOJO_READ_DATA_FLAG_DISCARD| - Discard (up to) the requested number of 83 // |MOJO_READ_DATA_FLAG_DISCARD| - Discard (up to) the requested number of
76 // elements. 84 // elements.
77 // |MOJO_READ_DATA_FLAG_QUERY| - Query the number of elements available to 85 // |MOJO_READ_DATA_FLAG_QUERY| - Query the number of elements available to
78 // read. For use with |MojoReadData()| only. Mutually exclusive with 86 // read. For use with |MojoReadData()| only. Mutually exclusive with
79 // |MOJO_READ_DATA_FLAG_DISCARD|, and |MOJO_READ_DATA_FLAG_ALL_OR_NONE| 87 // |MOJO_READ_DATA_FLAG_DISCARD|, and |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
80 // is ignored if this flag is set. 88 // is ignored if this flag is set.
81 // |MOJO_READ_DATA_FLAG_PEEK| - Read elements without removing them. For use 89 // |MOJO_READ_DATA_FLAG_PEEK| - Read elements without removing them. For use
82 // with |MojoReadData()| only. Mutually exclusive with 90 // with |MojoReadData()| only. Mutually exclusive with
83 // |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_QUERY|. 91 // |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_QUERY|.
84 92
(...skipping 14 matching lines...) Expand all
99 #endif 107 #endif
100 108
101 #ifdef __cplusplus 109 #ifdef __cplusplus
102 extern "C" { 110 extern "C" {
103 #endif 111 #endif
104 112
105 // Note: See the comment in functions.h about the meaning of the "optional" 113 // Note: See the comment in functions.h about the meaning of the "optional"
106 // label for pointer parameters. 114 // label for pointer parameters.
107 115
108 // Creates a data pipe, which is a unidirectional communication channel for 116 // Creates a data pipe, which is a unidirectional communication channel for
109 // unframed data, with the given options. Data is unframed, but must come as 117 // unframed data. Data must be read and written in multiples of discrete
110 // (multiples of) discrete elements, of the size given in |options|. See 118 // discrete elements of size given in |options|.
111 // |MojoCreateDataPipeOptions| for a description of the different options 119 //
120 // See |MojoCreateDataPipeOptions| for a description of the different options
112 // available for data pipes. 121 // available for data pipes.
113 // 122 //
114 // |options| may be set to null for a data pipe with the default options (which 123 // |options| may be set to null for a data pipe with the default options (which
115 // will have an element size of one byte and have some system-dependent 124 // will have an element size of one byte and have some system-dependent
116 // capacity). 125 // capacity).
117 // 126 //
118 // On success, |*data_pipe_producer_handle| will be set to the handle for the 127 // On success, |*data_pipe_producer_handle| will be set to the handle for the
119 // producer and |*data_pipe_consumer_handle| will be set to the handle for the 128 // producer and |*data_pipe_consumer_handle| will be set to the handle for the
120 // consumer. (On failure, they are not modified.) 129 // consumer. On failure they are not modified.
121 // 130 //
122 // Returns: 131 // Returns:
123 // |MOJO_RESULT_OK| on success. 132 // |MOJO_RESULT_OK| on success.
124 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 133 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
125 // |*options| is invalid). 134 // |*options| is invalid).
126 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has 135 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has
127 // been reached (e.g., if the requested capacity was too large, or if the 136 // been reached (e.g., if the requested capacity was too large, or if the
128 // maximum number of handles was exceeded). 137 // maximum number of handles was exceeded).
129 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. 138 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|.
130 MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe( 139 MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe(
131 const struct MojoCreateDataPipeOptions* options, // Optional. 140 const struct MojoCreateDataPipeOptions* options, // Optional.
132 MojoHandle* data_pipe_producer_handle, // Out. 141 MojoHandle* data_pipe_producer_handle, // Out.
133 MojoHandle* data_pipe_consumer_handle); // Out. 142 MojoHandle* data_pipe_consumer_handle); // Out.
134 143
135 // Writes the given data to the data pipe producer given by 144 // Writes the data pipe producer given by |data_pipe_producer_handle|.
136 // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|; 145 //
137 // |*num_bytes| should be a multiple of the data pipe's element size. If 146 // |elements| points to data of size |*num_bytes|; |*num_bytes| must be a
147 // multiple of the data pipe's element size. If
138 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data 148 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data
139 // will be written or none is. 149 // is written (if enough write capacity is available) or none is.
140 // 150 //
141 // On success, |*num_bytes| is set to the amount of data that was actually 151 // On success |*num_bytes| is set to the amount of data that was actually
142 // written. 152 // written. On failure it is unmodified.
143 //
144 // Note: If the data pipe has the "may discard" option flag (specified on
145 // creation), this will discard as much data as required to write the given
146 // data, starting with the earliest written data that has not been consumed.
147 // However, even with "may discard", if |*num_bytes| is greater than the data
148 // pipe's capacity (and |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is not set), this
149 // will write the maximum amount possible (namely, the data pipe's capacity) and
150 // set |*num_bytes| to that amount. It will *not* discard data from |elements|.
151 // 153 //
152 // Returns: 154 // Returns:
153 // |MOJO_RESULT_OK| on success. 155 // |MOJO_RESULT_OK| on success.
154 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 156 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
155 // |data_pipe_producer_dispatcher| is not a handle to a data pipe 157 // |data_pipe_producer_dispatcher| is not a handle to a data pipe
156 // producer or |*num_bytes| is not a multiple of the data pipe's element 158 // producer or |*num_bytes| is not a multiple of the data pipe's element
157 // size). 159 // size.)
158 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been 160 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been
159 // closed. 161 // closed.
160 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has 162 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has
161 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data 163 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data
162 // (specified by |*num_bytes|) could not be written. 164 // (specified by |*num_bytes|) could not be written.
163 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with 165 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with
164 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been 166 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been
165 // called, but not yet the matching |MojoEndWriteData()|). 167 // called, but not yet the matching |MojoEndWriteData()|).
166 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the 168 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
167 // consumer is still open) and |flags| does *not* have 169 // consumer is still open) and |flags| does *not* have
168 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. 170 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set.
169 //
170 // TODO(vtl): Should there be a way of querying how much data can be written?
171 MOJO_SYSTEM_EXPORT MojoResult 171 MOJO_SYSTEM_EXPORT MojoResult
172 MojoWriteData(MojoHandle data_pipe_producer_handle, 172 MojoWriteData(MojoHandle data_pipe_producer_handle,
173 const void* elements, 173 const void* elements,
174 uint32_t* num_bytes, // In/out. 174 uint32_t* num_bytes, // In/out.
175 MojoWriteDataFlags flags); 175 MojoWriteDataFlags flags);
176 176
177 // Begins a two-phase write to the data pipe producer given by 177 // Begins a two-phase write to the data pipe producer given by
178 // |data_pipe_producer_handle|. On success, |*buffer| will be a pointer to which 178 // |data_pipe_producer_handle|. On success |*buffer| will be a pointer to which
179 // the caller can write |*buffer_num_bytes| bytes of data. If flags has 179 // the caller can write up to |*buffer_num_bytes| bytes of data.
180 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set, then the output value
181 // |*buffer_num_bytes| will be at least as large as its input value, which must
182 // also be a multiple of the element size (if |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE|
183 // is not set, the input value of |*buffer_num_bytes| is ignored).
184 // 180 //
185 // During a two-phase write, |data_pipe_producer_handle| is *not* writable. 181 // During a two-phase write, |data_pipe_producer_handle| is *not* writable.
186 // E.g., if another thread tries to write to it, it will get |MOJO_RESULT_BUSY|; 182 // If another caller tries to write to it by calling |MojoWriteData()| or
187 // that thread can then wait for |data_pipe_producer_handle| to become writable 183 // |MojoBeginWriteData()|, their request will fail with |MOJO_RESULT_BUSY|.
188 // again.
189 // 184 //
190 // When |MojoBeginWriteData()| returns MOJO_RESULT_OK, and the caller has 185 // If |MojoBeginWriteData()| returns MOJO_RESULT_OK and once the caller has
191 // finished writing data to |*buffer|, it should call |MojoEndWriteData()| to 186 // finished writing data to |*buffer|, |MojoEndWriteData()| must be called to
192 // specify the amount written and to complete the two-phase write. 187 // indicate the amount of data actually written and to complete the two-phase
193 // |MojoEndWriteData()| need not be called for other return values. 188 // write operation. |MojoEndWriteData()| need not be called when
194 // 189 // |MojoBeginWriteData()| fails.
195 // Note: If the data pipe has the "may discard" option flag (specified on
196 // creation) and |flags| has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set, this may
197 // discard some data.
198 // 190 //
199 // Returns: 191 // Returns:
200 // |MOJO_RESULT_OK| on success. 192 // |MOJO_RESULT_OK| on success.
201 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 193 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
202 // |data_pipe_producer_handle| is not a handle to a data pipe producer or 194 // |data_pipe_producer_handle| is not a handle to a data pipe producer or
203 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and 195 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set.
204 // |*buffer_num_bytes| is not a multiple of the element size).
205 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been 196 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been
206 // closed. 197 // closed.
207 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has
208 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data
209 // (specified by |*buffer_num_bytes|) cannot be written contiguously at
210 // this time. (Note that there may be space available for the required
211 // amount of data, but the "next" write position may not be large enough.)
212 // |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with 198 // |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with
213 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been 199 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been
214 // called, but not yet the matching |MojoEndWriteData()|). 200 // called, but not yet the matching |MojoEndWriteData()|).
215 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the 201 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
216 // consumer is still open). 202 // consumer is still open).
217 MOJO_SYSTEM_EXPORT MojoResult 203 MOJO_SYSTEM_EXPORT MojoResult
218 MojoBeginWriteData(MojoHandle data_pipe_producer_handle, 204 MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
219 void** buffer, // Out. 205 void** buffer, // Out.
220 uint32_t* buffer_num_bytes, // In/out. 206 uint32_t* buffer_num_bytes, // In/out.
221 MojoWriteDataFlags flags); 207 MojoWriteDataFlags flags);
222 208
223 // Ends a two-phase write to the data pipe producer given by 209 // Ends a two-phase write that was previously initiated by
224 // |data_pipe_producer_handle| that was begun by a call to 210 // |MojoBeginWriteData()| for the same |data_pipe_producer_handle|.
225 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should 211 //
226 // indicate the amount of data actually written; it must be less than or equal 212 // |num_bytes_written| must indicate the number of bytes actually written into
227 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must 213 // the two-phase write buffer. It must be less than or equal to the value of
228 // be a multiple of the element size. The buffer given by |*buffer| from 214 // |*buffer_num_bytes| output by |MojoBeginWriteData()|, and it must be a
229 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written| 215 // multiple of the data pipe's element size.
230 // bytes of data.
231 // 216 //
232 // On failure, the two-phase write (if any) is ended (so the handle may become 217 // On failure, the two-phase write (if any) is ended (so the handle may become
233 // writable again, if there's space available) but no data written to |*buffer| 218 // writable again if there's space available) but no data written to |*buffer|
234 // is "put into" the data pipe. 219 // is "put into" the data pipe.
235 // 220 //
236 // Returns: 221 // Returns:
237 // |MOJO_RESULT_OK| on success. 222 // |MOJO_RESULT_OK| on success.
238 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 223 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
239 // |data_pipe_producer_handle| is not a handle to a data pipe producer or 224 // |data_pipe_producer_handle| is not a handle to a data pipe producer or
240 // |num_bytes_written| is invalid (greater than the maximum value provided 225 // |num_bytes_written| is invalid (greater than the maximum value provided
241 // by |MojoBeginWriteData()| or not a multiple of the element size). 226 // by |MojoBeginWriteData()| or not a multiple of the element size).
242 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a 227 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a
243 // two-phase write (e.g., |MojoBeginWriteData()| was not called or 228 // two-phase write (e.g., |MojoBeginWriteData()| was not called or
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and 275 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and
291 // the producer is still open) and |flags| does *not* have 276 // the producer is still open) and |flags| does *not* have
292 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. 277 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set.
293 MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, 278 MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
294 void* elements, // Out. 279 void* elements, // Out.
295 uint32_t* num_bytes, // In/out. 280 uint32_t* num_bytes, // In/out.
296 MojoReadDataFlags flags); 281 MojoReadDataFlags flags);
297 282
298 // Begins a two-phase read from the data pipe consumer given by 283 // Begins a two-phase read from the data pipe consumer given by
299 // |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from 284 // |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from
300 // which the caller can read |*buffer_num_bytes| bytes of data. If flags has 285 // which the caller can read up to |*buffer_num_bytes| bytes of data.
301 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, then the output value
302 // |*buffer_num_bytes| will be at least as large as its input value, which must
303 // also be a multiple of the element size (if |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
304 // is not set, the input value of |*buffer_num_bytes| is ignored). |flags| must
305 // not have |MOJO_READ_DATA_FLAG_DISCARD|, |MOJO_READ_DATA_FLAG_QUERY|, or
306 // |MOJO_READ_DATA_FLAG_PEEK| set.
307 // 286 //
308 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable. 287 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable.
309 // E.g., if another thread tries to read from it, it will get 288 // If another caller tries to read from it by calling |MojoReadData()| or
310 // |MOJO_RESULT_BUSY|; that thread can then wait for |data_pipe_consumer_handle| 289 // |MojoBeginReadData()|, their request will fail with |MOJO_RESULT_BUSY|.
311 // to become readable again.
312 // 290 //
313 // Once the caller has finished reading data from |*buffer|, it should call 291 // Once the caller has finished reading data from |*buffer|, |MojoEndReadData()|
314 // |MojoEndReadData()| to specify the amount read and to complete the two-phase 292 // must be called to indicate the number of bytes read and to complete the
315 // read. 293 // two-phase read operation.
294 //
295 // |flags| must not have |MOJO_READ_DATA_FLAG_DISCARD|,
296 // |MOJO_READ_DATA_FLAG_QUERY|, |MOJO_READ_DATA_FLAG_PEEK|, or
297 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set.
316 // 298 //
317 // Returns: 299 // Returns:
318 // |MOJO_RESULT_OK| on success. 300 // |MOJO_RESULT_OK| on success.
319 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 301 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
320 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer, 302 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer,
321 // |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set and 303 // or |flags| has invalid flags set.)
322 // |*buffer_num_bytes| is not a multiple of the element size, or |flags|
323 // has invalid flags set).
324 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been 304 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been
325 // closed. 305 // closed.
326 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
327 // set and the required amount of data (specified by |*buffer_num_bytes|)
328 // cannot be read from a contiguous buffer at this time. (Note that there
329 // may be the required amount of data, but it may not be contiguous.)
330 // |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with 306 // |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with
331 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been 307 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been
332 // called, but not yet the matching |MojoEndReadData()|). 308 // called, but not yet the matching |MojoEndReadData()|).
333 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the 309 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the
334 // producer is still open). 310 // producer is still open).
335 MOJO_SYSTEM_EXPORT MojoResult 311 MOJO_SYSTEM_EXPORT MojoResult
336 MojoBeginReadData(MojoHandle data_pipe_consumer_handle, 312 MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
337 const void** buffer, // Out. 313 const void** buffer, // Out.
338 uint32_t* buffer_num_bytes, // In/out. 314 uint32_t* buffer_num_bytes, // In/out.
339 MojoReadDataFlags flags); 315 MojoReadDataFlags flags);
(...skipping 19 matching lines...) Expand all
359 // |MojoEndReadData()| has already been called). 335 // |MojoEndReadData()| has already been called).
360 MOJO_SYSTEM_EXPORT MojoResult 336 MOJO_SYSTEM_EXPORT MojoResult
361 MojoEndReadData(MojoHandle data_pipe_consumer_handle, 337 MojoEndReadData(MojoHandle data_pipe_consumer_handle,
362 uint32_t num_bytes_read); 338 uint32_t num_bytes_read);
363 339
364 #ifdef __cplusplus 340 #ifdef __cplusplus
365 } // extern "C" 341 } // extern "C"
366 #endif 342 #endif
367 343
368 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ 344 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698