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

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

Issue 1374463002: Remove support for "all or none" two-phase data pipe read/write. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: oops Created 5 years, 2 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
« no previous file with comments | « mojo/go/tests/system_test.go ('k') | mojo/public/go/bindings/invalid_handle.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 // Writes the given data to the data pipe producer given by 133 // Writes the given data to the data pipe producer given by
134 // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|; 134 // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|;
135 // |*num_bytes| should be a multiple of the data pipe's element size. If 135 // |*num_bytes| should be a multiple of the data pipe's element size. If
136 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data 136 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data
137 // will be written or none is. 137 // will be written or none is.
138 // 138 //
139 // On success, |*num_bytes| is set to the amount of data that was actually 139 // On success, |*num_bytes| is set to the amount of data that was actually
140 // written. 140 // written.
141 // 141 //
142 // Note: If the data pipe has the "may discard" option flag (specified on
143 // creation), this will discard as much data as required to write the given
144 // data, starting with the earliest written data that has not been consumed.
145 // However, even with "may discard", if |*num_bytes| is greater than the data
146 // pipe's capacity (and |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is not set), this
147 // will write the maximum amount possible (namely, the data pipe's capacity) and
148 // set |*num_bytes| to that amount. It will *not* discard data from |elements|.
149 //
150 // Returns: 142 // Returns:
151 // |MOJO_RESULT_OK| on success. 143 // |MOJO_RESULT_OK| on success.
152 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 144 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
153 // |data_pipe_producer_dispatcher| is not a handle to a data pipe 145 // |data_pipe_producer_dispatcher| is not a handle to a data pipe
154 // producer or |*num_bytes| is not a multiple of the data pipe's element 146 // producer or |*num_bytes| is not a multiple of the data pipe's element
155 // size). 147 // size).
156 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been 148 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been
157 // closed. 149 // closed.
158 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has 150 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has
159 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data 151 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data
160 // (specified by |*num_bytes|) could not be written. 152 // (specified by |*num_bytes|) could not be written.
161 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with 153 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with
162 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been 154 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been
163 // called, but not yet the matching |MojoEndWriteData()|). 155 // called, but not yet the matching |MojoEndWriteData()|).
164 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the 156 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
165 // consumer is still open) and |flags| does *not* have 157 // consumer is still open) and |flags| does *not* have
166 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. 158 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set.
167 // 159 //
168 // TODO(vtl): Should there be a way of querying how much data can be written? 160 // TODO(vtl): Should there be a way of querying how much data can be written?
169 MOJO_SYSTEM_EXPORT MojoResult 161 MOJO_SYSTEM_EXPORT MojoResult
170 MojoWriteData(MojoHandle data_pipe_producer_handle, 162 MojoWriteData(MojoHandle data_pipe_producer_handle,
171 const void* elements, 163 const void* elements,
172 uint32_t* num_bytes, // In/out. 164 uint32_t* num_bytes, // In/out.
173 MojoWriteDataFlags flags); 165 MojoWriteDataFlags flags);
174 166
175 // Begins a two-phase write to the data pipe producer given by 167 // Begins a two-phase write to the data pipe producer given by
176 // |data_pipe_producer_handle|. On success, |*buffer| will be a pointer to which 168 // |data_pipe_producer_handle|. On success, |*buffer| will be a pointer to which
177 // the caller can write |*buffer_num_bytes| bytes of data. If flags has 169 // the caller can write |*buffer_num_bytes| bytes of data. There are currently
178 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set, then the output value 170 // no flags allowed, so |flags| should be |MOJO_WRITE_DATA_FLAG_NONE|.
179 // |*buffer_num_bytes| will be at least as large as its input value, which must
180 // also be a multiple of the element size (if |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE|
181 // is not set, the input value of |*buffer_num_bytes| is ignored).
182 // 171 //
183 // During a two-phase write, |data_pipe_producer_handle| is *not* writable. 172 // During a two-phase write, |data_pipe_producer_handle| is *not* writable.
184 // E.g., if another thread tries to write to it, it will get |MOJO_RESULT_BUSY|; 173 // E.g., if another thread tries to write to it, it will get |MOJO_RESULT_BUSY|;
185 // that thread can then wait for |data_pipe_producer_handle| to become writable 174 // that thread can then wait for |data_pipe_producer_handle| to become writable
186 // again. 175 // again.
187 // 176 //
188 // When |MojoBeginWriteData()| returns MOJO_RESULT_OK, and the caller has 177 // When |MojoBeginWriteData()| returns |MOJO_RESULT_OK|, and the caller has
189 // finished writing data to |*buffer|, it should call |MojoEndWriteData()| to 178 // finished writing data to |*buffer|, it should call |MojoEndWriteData()| to
190 // specify the amount written and to complete the two-phase write. 179 // specify the amount written and to complete the two-phase write.
191 // |MojoEndWriteData()| need not be called for other return values. 180 // |MojoEndWriteData()| need not be called for other return values.
192 // 181 //
193 // Note: If the data pipe has the "may discard" option flag (specified on
194 // creation) and |flags| has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set, this may
195 // discard some data.
196 //
197 // Returns: 182 // Returns:
198 // |MOJO_RESULT_OK| on success. 183 // |MOJO_RESULT_OK| on success.
199 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 184 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
200 // |data_pipe_producer_handle| is not a handle to a data pipe producer or 185 // |data_pipe_producer_handle| is not a handle to a data pipe producer or
201 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and 186 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set).
202 // |*buffer_num_bytes| is not a multiple of the element size).
203 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been 187 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been
204 // closed. 188 // closed.
205 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has
206 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data
207 // (specified by |*buffer_num_bytes|) cannot be written contiguously at
208 // this time. (Note that there may be space available for the required
209 // amount of data, but the "next" write position may not be large enough.)
210 // |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with 189 // |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with
211 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been 190 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been
212 // called, but not yet the matching |MojoEndWriteData()|). 191 // called, but not yet the matching |MojoEndWriteData()|).
213 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the 192 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
214 // consumer is still open). 193 // consumer is still open).
215 MOJO_SYSTEM_EXPORT MojoResult 194 MOJO_SYSTEM_EXPORT MojoResult
216 MojoBeginWriteData(MojoHandle data_pipe_producer_handle, 195 MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
217 void** buffer, // Out. 196 void** buffer, // Out.
218 uint32_t* buffer_num_bytes, // In/out. 197 uint32_t* buffer_num_bytes, // Out.
219 MojoWriteDataFlags flags); 198 MojoWriteDataFlags flags);
220 199
221 // Ends a two-phase write to the data pipe producer given by 200 // Ends a two-phase write to the data pipe producer given by
222 // |data_pipe_producer_handle| that was begun by a call to 201 // |data_pipe_producer_handle| that was begun by a call to
223 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should 202 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should
224 // indicate the amount of data actually written; it must be less than or equal 203 // indicate the amount of data actually written; it must be less than or equal
225 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must 204 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must
226 // be a multiple of the element size. The buffer given by |*buffer| from 205 // be a multiple of the element size. The buffer given by |*buffer| from
227 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written| 206 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written|
228 // bytes of data. 207 // bytes of data.
229 // 208 //
230 // On failure, the two-phase write (if any) is ended (so the handle may become 209 // On failure, the two-phase write (if any) is ended (so the handle may become
231 // writable again, if there's space available) but no data written to |*buffer| 210 // writable again, if there's space available) but no data written to |*buffer|
232 // is "put into" the data pipe. 211 // is "put into" the data pipe.
233 // 212 //
234 // Returns: 213 // Returns:
235 // |MOJO_RESULT_OK| on success. 214 // |MOJO_RESULT_OK| on success.
236 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 215 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
237 // |data_pipe_producer_handle| is not a handle to a data pipe producer or 216 // |data_pipe_producer_handle| is not a handle to a data pipe producer or
238 // |num_bytes_written| is invalid (greater than the maximum value provided 217 // |num_bytes_written| is invalid (greater than the maximum value provided
239 // by |MojoBeginWriteData()| or not a multiple of the element size). 218 // by |MojoBeginWriteData()| or not a multiple of the element size).
240 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a 219 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a
241 // two-phase write (e.g., |MojoBeginWriteData()| was not called or 220 // two-phase write (e.g., |MojoBeginWriteData()| was not called or
242 // |MojoEndWriteData()| has already been called). 221 // |MojoEndWriteData()| has already been called).
243 MOJO_SYSTEM_EXPORT MojoResult 222 MOJO_SYSTEM_EXPORT MojoResult
244 MojoEndWriteData(MojoHandle data_pipe_producer_handle, 223 MojoEndWriteData(MojoHandle data_pipe_producer_handle,
245 uint32_t num_bytes_written); 224 uint32_t num_bytes_written);
246 225
247 // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|. 226 // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|.
248 // May also be used to discard data or query the amount of data available. 227 // May also be used to discard data or query the amount of data available.
249 // 228 //
250 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor 229 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor
251 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which 230 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which
252 // must be a multiple of the data pipe's element size) bytes of data to 231 // must be a multiple of the data pipe's element size) bytes of data to
253 // |elements| and set |*num_bytes| to the amount actually read. If flags has 232 // |elements| and set |*num_bytes| to the amount actually read. If flags has
254 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly 233 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly
255 // |*num_bytes| bytes of data or none. Additionally, if flags has 234 // |*num_bytes| bytes of data or none. Additionally, if flags has
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and 267 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and
289 // the producer is still open) and |flags| does *not* have 268 // the producer is still open) and |flags| does *not* have
290 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. 269 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set.
291 MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, 270 MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
292 void* elements, // Out. 271 void* elements, // Out.
293 uint32_t* num_bytes, // In/out. 272 uint32_t* num_bytes, // In/out.
294 MojoReadDataFlags flags); 273 MojoReadDataFlags flags);
295 274
296 // Begins a two-phase read from the data pipe consumer given by 275 // 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 276 // |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 277 // which the caller can read |*buffer_num_bytes| bytes of data. There are
299 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, then the output value 278 // currently no valid flags, so |flags| must be |MOJO_READ_DATA_FLAG_NONE|.
300 // |*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|
302 // is not set, the input value of |*buffer_num_bytes| is ignored). |flags| must
303 // not have |MOJO_READ_DATA_FLAG_DISCARD|, |MOJO_READ_DATA_FLAG_QUERY|, or
304 // |MOJO_READ_DATA_FLAG_PEEK| set.
305 // 279 //
306 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable. 280 // During a two-phase read, |data_pipe_consumer_handle| is *not* readable.
307 // E.g., if another thread tries to read from it, it will get 281 // E.g., if another thread tries to read from it, it will get
308 // |MOJO_RESULT_BUSY|; that thread can then wait for |data_pipe_consumer_handle| 282 // |MOJO_RESULT_BUSY|; that thread can then wait for |data_pipe_consumer_handle|
309 // to become readable again. 283 // to become readable again.
310 // 284 //
311 // Once the caller has finished reading data from |*buffer|, it should call 285 // Once the caller has finished reading data from |*buffer|, it should call
312 // |MojoEndReadData()| to specify the amount read and to complete the two-phase 286 // |MojoEndReadData()| to specify the amount read and to complete the two-phase
313 // read. 287 // read.
314 // 288 //
315 // Returns: 289 // Returns:
316 // |MOJO_RESULT_OK| on success. 290 // |MOJO_RESULT_OK| on success.
317 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 291 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
318 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer, 292 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer,
319 // |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set and 293 // or |flags| has invalid flags set).
320 // |*buffer_num_bytes| is not a multiple of the element size, or |flags|
321 // has invalid flags set).
322 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been 294 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been
323 // closed. 295 // closed.
324 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
325 // set and the required amount of data (specified by |*buffer_num_bytes|)
326 // cannot be read from a contiguous buffer at this time. (Note that there
327 // may be the required amount of data, but it may not be contiguous.)
328 // |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with 296 // |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with
329 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been 297 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been
330 // called, but not yet the matching |MojoEndReadData()|). 298 // called, but not yet the matching |MojoEndReadData()|).
331 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the 299 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the
332 // producer is still open). 300 // producer is still open).
333 MOJO_SYSTEM_EXPORT MojoResult 301 MOJO_SYSTEM_EXPORT MojoResult
334 MojoBeginReadData(MojoHandle data_pipe_consumer_handle, 302 MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
335 const void** buffer, // Out. 303 const void** buffer, // Out.
336 uint32_t* buffer_num_bytes, // In/out. 304 uint32_t* buffer_num_bytes, // Out.
337 MojoReadDataFlags flags); 305 MojoReadDataFlags flags);
338 306
339 // Ends a two-phase read from the data pipe consumer given by 307 // Ends a two-phase read from the data pipe consumer given by
340 // |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()| 308 // |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()|
341 // on the same handle. |num_bytes_read| should indicate the amount of data 309 // on the same handle. |num_bytes_read| should indicate the amount of data
342 // actually read; it must be less than or equal to the value of 310 // actually read; it must be less than or equal to the value of
343 // |*buffer_num_bytes| output by |MojoBeginReadData()| and must be a multiple of 311 // |*buffer_num_bytes| output by |MojoBeginReadData()| and must be a multiple of
344 // the element size. 312 // the element size.
345 // 313 //
346 // On failure, the two-phase read (if any) is ended (so the handle may become 314 // On failure, the two-phase read (if any) is ended (so the handle may become
347 // readable again) but no data is "removed" from the data pipe. 315 // readable again) but no data is "removed" from the data pipe.
348 // 316 //
349 // Returns: 317 // Returns:
350 // |MOJO_RESULT_OK| on success. 318 // |MOJO_RESULT_OK| on success.
351 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., 319 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
352 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or 320 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or
353 // |num_bytes_written| is greater than the maximum value provided by 321 // |num_bytes_written| is greater than the maximum value provided by
354 // |MojoBeginReadData()| or not a multiple of the element size). 322 // |MojoBeginReadData()| or not a multiple of the element size).
355 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a 323 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a
356 // two-phase read (e.g., |MojoBeginReadData()| was not called or 324 // two-phase read (e.g., |MojoBeginReadData()| was not called or
357 // |MojoEndReadData()| has already been called). 325 // |MojoEndReadData()| has already been called).
358 MOJO_SYSTEM_EXPORT MojoResult 326 MOJO_SYSTEM_EXPORT MojoResult
359 MojoEndReadData(MojoHandle data_pipe_consumer_handle, 327 MojoEndReadData(MojoHandle data_pipe_consumer_handle, uint32_t num_bytes_read);
360 uint32_t num_bytes_read);
361 328
362 #ifdef __cplusplus 329 #ifdef __cplusplus
363 } // extern "C" 330 } // extern "C"
364 #endif 331 #endif
365 332
366 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ 333 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_
OLDNEW
« no previous file with comments | « mojo/go/tests/system_test.go ('k') | mojo/public/go/bindings/invalid_handle.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698