| 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 17 matching lines...) Expand all Loading... |
| 28 // elements. Must be nonzero. | 28 // elements. Must be nonzero. |
| 29 // |uint32_t capacity_num_bytes|: The capacity of the data pipe, in number of | 29 // |uint32_t capacity_num_bytes|: The capacity of the data pipe, in number of |
| 30 // bytes; must be a multiple of |element_num_bytes|. The data pipe will | 30 // bytes; must be a multiple of |element_num_bytes|. The data pipe will |
| 31 // always be able to queue AT LEAST this much data. Set to zero to opt for | 31 // always be able to queue AT LEAST this much data. Set to zero to opt for |
| 32 // a system-dependent automatically-calculated capacity (which will always | 32 // a system-dependent automatically-calculated capacity (which will always |
| 33 // be at least one element). | 33 // be at least one element). |
| 34 | 34 |
| 35 typedef uint32_t MojoCreateDataPipeOptionsFlags; | 35 typedef uint32_t MojoCreateDataPipeOptionsFlags; |
| 36 | 36 |
| 37 #ifdef __cplusplus | 37 #ifdef __cplusplus |
| 38 const MojoCreateDataPipeOptionsFlags | 38 const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE = |
| 39 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE = 0; | 39 0; |
| 40 const MojoCreateDataPipeOptionsFlags | 40 const MojoCreateDataPipeOptionsFlags |
| 41 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD = 1 << 0; | 41 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD = 1 << 0; |
| 42 #else | 42 #else |
| 43 #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE \ | 43 #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE \ |
| 44 ((MojoCreateDataPipeOptionsFlags) 0) | 44 ((MojoCreateDataPipeOptionsFlags)0) |
| 45 #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD \ | 45 #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD \ |
| 46 ((MojoCreateDataPipeOptionsFlags) 1 << 0) | 46 ((MojoCreateDataPipeOptionsFlags)1 << 0) |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); | 49 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); |
| 50 struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions { | 50 struct MOJO_ALIGNAS(8) MojoCreateDataPipeOptions { |
| 51 uint32_t struct_size; | 51 uint32_t struct_size; |
| 52 MojoCreateDataPipeOptionsFlags flags; | 52 MojoCreateDataPipeOptionsFlags flags; |
| 53 uint32_t element_num_bytes; | 53 uint32_t element_num_bytes; |
| 54 uint32_t capacity_num_bytes; | 54 uint32_t capacity_num_bytes; |
| 55 }; | 55 }; |
| 56 MOJO_COMPILE_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16, | 56 MOJO_COMPILE_ASSERT(sizeof(MojoCreateDataPipeOptions) == 16, |
| 57 MojoCreateDataPipeOptions_has_wrong_size); | 57 MojoCreateDataPipeOptions_has_wrong_size); |
| 58 | 58 |
| 59 // |MojoWriteDataFlags|: Used to specify different modes to |MojoWriteData()| | 59 // |MojoWriteDataFlags|: Used to specify different modes to |MojoWriteData()| |
| 60 // and |MojoBeginWriteData()|. | 60 // and |MojoBeginWriteData()|. |
| 61 // |MOJO_WRITE_DATA_FLAG_NONE| - No flags; default mode. | 61 // |MOJO_WRITE_DATA_FLAG_NONE| - No flags; default mode. |
| 62 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| - Write either all the elements | 62 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| - Write either all the elements |
| 63 // requested or none of them. | 63 // requested or none of them. |
| 64 | 64 |
| 65 typedef uint32_t MojoWriteDataFlags; | 65 typedef uint32_t MojoWriteDataFlags; |
| 66 | 66 |
| 67 #ifdef __cplusplus | 67 #ifdef __cplusplus |
| 68 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE = 0; | 68 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE = 0; |
| 69 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0; | 69 const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0; |
| 70 #else | 70 #else |
| 71 #define MOJO_WRITE_DATA_FLAG_NONE ((MojoWriteDataFlags) 0) | 71 #define MOJO_WRITE_DATA_FLAG_NONE ((MojoWriteDataFlags)0) |
| 72 #define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((MojoWriteDataFlags) 1 << 0) | 72 #define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((MojoWriteDataFlags)1 << 0) |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 // |MojoReadDataFlags|: Used to specify different modes to |MojoReadData()| and | 75 // |MojoReadDataFlags|: Used to specify different modes to |MojoReadData()| and |
| 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 | 86 |
| 87 typedef uint32_t MojoReadDataFlags; | 87 typedef uint32_t MojoReadDataFlags; |
| 88 | 88 |
| 89 #ifdef __cplusplus | 89 #ifdef __cplusplus |
| 90 const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE = 0; | 90 const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE = 0; |
| 91 const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0; | 91 const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0; |
| 92 const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1; | 92 const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1; |
| 93 const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2; | 93 const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2; |
| 94 #else | 94 #else |
| 95 #define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags) 0) | 95 #define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags)0) |
| 96 #define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags) 1 << 0) | 96 #define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags)1 << 0) |
| 97 #define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags) 1 << 1) | 97 #define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags)1 << 1) |
| 98 #define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags) 1 << 2) | 98 #define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags)1 << 2) |
| 99 #endif | 99 #endif |
| 100 | 100 |
| 101 #ifdef __cplusplus | 101 #ifdef __cplusplus |
| 102 extern "C" { | 102 extern "C" { |
| 103 #endif | 103 #endif |
| 104 | 104 |
| 105 // Note: See the comment in functions.h about the meaning of the "optional" | 105 // Note: See the comment in functions.h about the meaning of the "optional" |
| 106 // label for pointer parameters. | 106 // label for pointer parameters. |
| 107 | 107 |
| 108 // Creates a data pipe, which is a unidirectional communication channel for | 108 // Creates a data pipe, which is a unidirectional communication channel for |
| (...skipping 13 matching lines...) Expand all Loading... |
| 122 // Returns: | 122 // Returns: |
| 123 // |MOJO_RESULT_OK| on success. | 123 // |MOJO_RESULT_OK| on success. |
| 124 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 124 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 125 // |*options| is invalid). | 125 // |*options| is invalid). |
| 126 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | 126 // |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 | 127 // been reached (e.g., if the requested capacity was too large, or if the |
| 128 // maximum number of handles was exceeded). | 128 // maximum number of handles was exceeded). |
| 129 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 129 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
| 130 MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe( | 130 MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe( |
| 131 const struct MojoCreateDataPipeOptions* options, // Optional. | 131 const struct MojoCreateDataPipeOptions* options, // Optional. |
| 132 MojoHandle* data_pipe_producer_handle, // Out. | 132 MojoHandle* data_pipe_producer_handle, // Out. |
| 133 MojoHandle* data_pipe_consumer_handle); // Out. | 133 MojoHandle* data_pipe_consumer_handle); // Out. |
| 134 | 134 |
| 135 // Writes the given data to the data pipe producer given by | 135 // Writes the given data to the data pipe producer given by |
| 136 // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|; | 136 // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|; |
| 137 // |*num_bytes| should be a multiple of the data pipe's element size. If | 137 // |*num_bytes| should be a 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 | 138 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is set in |flags|, either all the data |
| 139 // will be written or none is. | 139 // will be written or none is. |
| 140 // | 140 // |
| 141 // On success, |*num_bytes| is set to the amount of data that was actually | 141 // On success, |*num_bytes| is set to the amount of data that was actually |
| 142 // written. | 142 // written. |
| 143 // | 143 // |
| (...skipping 17 matching lines...) Expand all Loading... |
| 161 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data | 161 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data |
| 162 // (specified by |*num_bytes|) could not be written. | 162 // (specified by |*num_bytes|) could not be written. |
| 163 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with | 163 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with |
| 164 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been | 164 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been |
| 165 // called, but not yet the matching |MojoEndWriteData()|). | 165 // called, but not yet the matching |MojoEndWriteData()|). |
| 166 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the | 166 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the |
| 167 // consumer is still open) and |flags| does *not* have | 167 // consumer is still open) and |flags| does *not* have |
| 168 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. | 168 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. |
| 169 // | 169 // |
| 170 // TODO(vtl): Should there be a way of querying how much data can be written? | 170 // TODO(vtl): Should there be a way of querying how much data can be written? |
| 171 MOJO_SYSTEM_EXPORT MojoResult MojoWriteData( | 171 MOJO_SYSTEM_EXPORT MojoResult |
| 172 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 |*buffer_num_bytes| bytes of data. If flags has |
| 180 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set, then the output value | 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 | 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| | 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). | 183 // is not set, the input value of |*buffer_num_bytes| is ignored). |
| 184 // | 184 // |
| 185 // During a two-phase write, |data_pipe_producer_handle| is *not* writable. | 185 // During a two-phase write, |data_pipe_producer_handle| is *not* writable. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 206 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has | 206 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |
| 207 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data | 207 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data |
| 208 // (specified by |*buffer_num_bytes|) cannot be written contiguously at | 208 // (specified by |*buffer_num_bytes|) cannot be written contiguously at |
| 209 // this time. (Note that there may be space available for the required | 209 // this time. (Note that there may be space available for the required |
| 210 // amount of data, but the "next" write position may not be large enough.) | 210 // amount of data, but the "next" write position may not be large enough.) |
| 211 // |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with | 211 // |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with |
| 212 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been | 212 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been |
| 213 // called, but not yet the matching |MojoEndWriteData()|). | 213 // called, but not yet the matching |MojoEndWriteData()|). |
| 214 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the | 214 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the |
| 215 // consumer is still open). | 215 // consumer is still open). |
| 216 MOJO_SYSTEM_EXPORT MojoResult MojoBeginWriteData( | 216 MOJO_SYSTEM_EXPORT MojoResult |
| 217 MojoHandle data_pipe_producer_handle, | 217 MojoBeginWriteData(MojoHandle data_pipe_producer_handle, |
| 218 void** buffer, // Out. | 218 void** buffer, // Out. |
| 219 uint32_t* buffer_num_bytes, // In/out. | 219 uint32_t* buffer_num_bytes, // In/out. |
| 220 MojoWriteDataFlags flags); | 220 MojoWriteDataFlags flags); |
| 221 | 221 |
| 222 // Ends a two-phase write to the data pipe producer given by | 222 // Ends a two-phase write to the data pipe producer given by |
| 223 // |data_pipe_producer_handle| that was begun by a call to | 223 // |data_pipe_producer_handle| that was begun by a call to |
| 224 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should | 224 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should |
| 225 // indicate the amount of data actually written; it must be less than or equal | 225 // indicate the amount of data actually written; it must be less than or equal |
| 226 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must | 226 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must |
| 227 // be a multiple of the element size. The buffer given by |*buffer| from | 227 // be a multiple of the element size. The buffer given by |*buffer| from |
| 228 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written| | 228 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written| |
| 229 // bytes of data. | 229 // bytes of data. |
| 230 // | 230 // |
| 231 // On failure, the two-phase write (if any) is ended (so the handle may become | 231 // On failure, the two-phase write (if any) is ended (so the handle may become |
| 232 // writable again, if there's space available) but no data written to |*buffer| | 232 // writable again, if there's space available) but no data written to |*buffer| |
| 233 // is "put into" the data pipe. | 233 // is "put into" the data pipe. |
| 234 // | 234 // |
| 235 // Returns: | 235 // Returns: |
| 236 // |MOJO_RESULT_OK| on success. | 236 // |MOJO_RESULT_OK| on success. |
| 237 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 237 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 238 // |data_pipe_producer_handle| is not a handle to a data pipe producer or | 238 // |data_pipe_producer_handle| is not a handle to a data pipe producer or |
| 239 // |num_bytes_written| is invalid (greater than the maximum value provided | 239 // |num_bytes_written| is invalid (greater than the maximum value provided |
| 240 // by |MojoBeginWriteData()| or not a multiple of the element size). | 240 // by |MojoBeginWriteData()| or not a multiple of the element size). |
| 241 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a | 241 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a |
| 242 // two-phase write (e.g., |MojoBeginWriteData()| was not called or | 242 // two-phase write (e.g., |MojoBeginWriteData()| was not called or |
| 243 // |MojoEndWriteData()| has already been called). | 243 // |MojoEndWriteData()| has already been called). |
| 244 MOJO_SYSTEM_EXPORT MojoResult MojoEndWriteData( | 244 MOJO_SYSTEM_EXPORT MojoResult |
| 245 MojoHandle data_pipe_producer_handle, | 245 MojoEndWriteData(MojoHandle data_pipe_producer_handle, |
| 246 uint32_t num_bytes_written); | 246 uint32_t num_bytes_written); |
| 247 | 247 |
| 248 // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|. | 248 // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|. |
| 249 // May also be used to discard data or query the amount of data available. | 249 // May also be used to discard data or query the amount of data available. |
| 250 // | 250 // |
| 251 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor | 251 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor |
| 252 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which | 252 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which |
| 253 // must be a multiple of the data pipe's element size) bytes of data to | 253 // must be a multiple of the data pipe's element size) bytes of data to |
| 254 // |elements| and set |*num_bytes| to the amount actually read. If flags has | 254 // |elements| and set |*num_bytes| to the amount actually read. If flags has |
| 255 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly | 255 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly |
| 256 // |*num_bytes| bytes of data or none. | 256 // |*num_bytes| bytes of data or none. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 280 // be read or discarded. | 280 // be read or discarded. |
| 281 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| | 281 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| |
| 282 // set and the required amount of data is not available to be read or | 282 // set and the required amount of data is not available to be read or |
| 283 // discarded (and the producer is still open). | 283 // discarded (and the producer is still open). |
| 284 // |MOJO_RESULT_BUSY| if there is a two-phase read ongoing with | 284 // |MOJO_RESULT_BUSY| if there is a two-phase read ongoing with |
| 285 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been | 285 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been |
| 286 // called, but not yet the matching |MojoEndReadData()|). | 286 // called, but not yet the matching |MojoEndReadData()|). |
| 287 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and | 287 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and |
| 288 // the producer is still open) and |flags| does *not* have | 288 // the producer is still open) and |flags| does *not* have |
| 289 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. | 289 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. |
| 290 MOJO_SYSTEM_EXPORT MojoResult MojoReadData( | 290 MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, |
| 291 MojoHandle data_pipe_consumer_handle, | 291 void* elements, // Out. |
| 292 void* elements, // Out. | 292 uint32_t* num_bytes, // In/out. |
| 293 uint32_t* num_bytes, // In/out. | 293 MojoReadDataFlags flags); |
| 294 MojoReadDataFlags flags); | |
| 295 | 294 |
| 296 // Begins a two-phase read from the data pipe consumer given by | 295 // 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 | 296 // |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 | 297 // 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 | 298 // |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 | 299 // |*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| | 300 // 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 | 301 // 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. | 302 // not have |MOJO_READ_DATA_FLAG_DISCARD| or |MOJO_READ_DATA_FLAG_QUERY| set. |
| 304 // | 303 // |
| (...skipping 17 matching lines...) Expand all Loading... |
| 322 // closed. | 321 // closed. |
| 323 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| | 322 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| |
| 324 // set and the required amount of data (specified by |*buffer_num_bytes|) | 323 // set and the required amount of data (specified by |*buffer_num_bytes|) |
| 325 // cannot be read from a contiguous buffer at this time. (Note that there | 324 // cannot be read from a contiguous buffer at this time. (Note that there |
| 326 // may be the required amount of data, but it may not be contiguous.) | 325 // may be the required amount of data, but it may not be contiguous.) |
| 327 // |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with | 326 // |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with |
| 328 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been | 327 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been |
| 329 // called, but not yet the matching |MojoEndReadData()|). | 328 // called, but not yet the matching |MojoEndReadData()|). |
| 330 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the | 329 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the |
| 331 // producer is still open). | 330 // producer is still open). |
| 332 MOJO_SYSTEM_EXPORT MojoResult MojoBeginReadData( | 331 MOJO_SYSTEM_EXPORT MojoResult |
| 333 MojoHandle data_pipe_consumer_handle, | 332 MojoBeginReadData(MojoHandle data_pipe_consumer_handle, |
| 334 const void** buffer, // Out. | 333 const void** buffer, // Out. |
| 335 uint32_t* buffer_num_bytes, // In/out. | 334 uint32_t* buffer_num_bytes, // In/out. |
| 336 MojoReadDataFlags flags); | 335 MojoReadDataFlags flags); |
| 337 | 336 |
| 338 // Ends a two-phase read from the data pipe consumer given by | 337 // Ends a two-phase read from the data pipe consumer given by |
| 339 // |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()| | 338 // |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()| |
| 340 // on the same handle. |num_bytes_read| should indicate the amount of data | 339 // on the same handle. |num_bytes_read| should indicate the amount of data |
| 341 // actually read; it must be less than or equal to the value of | 340 // actually read; it must be less than or equal to the value of |
| 342 // |*buffer_num_bytes| output by |MojoBeginReadData()| and must be a multiple of | 341 // |*buffer_num_bytes| output by |MojoBeginReadData()| and must be a multiple of |
| 343 // the element size. | 342 // the element size. |
| 344 // | 343 // |
| 345 // On failure, the two-phase read (if any) is ended (so the handle may become | 344 // On failure, the two-phase read (if any) is ended (so the handle may become |
| 346 // readable again) but no data is "removed" from the data pipe. | 345 // readable again) but no data is "removed" from the data pipe. |
| 347 // | 346 // |
| 348 // Returns: | 347 // Returns: |
| 349 // |MOJO_RESULT_OK| on success. | 348 // |MOJO_RESULT_OK| on success. |
| 350 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 349 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 351 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or | 350 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or |
| 352 // |num_bytes_written| is greater than the maximum value provided by | 351 // |num_bytes_written| is greater than the maximum value provided by |
| 353 // |MojoBeginReadData()| or not a multiple of the element size). | 352 // |MojoBeginReadData()| or not a multiple of the element size). |
| 354 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a | 353 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a |
| 355 // two-phase read (e.g., |MojoBeginReadData()| was not called or | 354 // two-phase read (e.g., |MojoBeginReadData()| was not called or |
| 356 // |MojoEndReadData()| has already been called). | 355 // |MojoEndReadData()| has already been called). |
| 357 MOJO_SYSTEM_EXPORT MojoResult MojoEndReadData( | 356 MOJO_SYSTEM_EXPORT MojoResult |
| 358 MojoHandle data_pipe_consumer_handle, | 357 MojoEndReadData(MojoHandle data_pipe_consumer_handle, |
| 359 uint32_t num_bytes_read); | 358 uint32_t num_bytes_read); |
| 360 | 359 |
| 361 #ifdef __cplusplus | 360 #ifdef __cplusplus |
| 362 } // extern "C" | 361 } // extern "C" |
| 363 #endif | 362 #endif |
| 364 | 363 |
| 365 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ | 364 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ |
| OLD | NEW |