| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // |MOJO_RESULT_OK| on success. | 121 // |MOJO_RESULT_OK| on success. |
| 122 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 122 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 123 // |data_pipe_producer_dispatcher| is not a handle to a data pipe | 123 // |data_pipe_producer_dispatcher| is not a handle to a data pipe |
| 124 // producer or |*num_bytes| is not a multiple of the data pipe's element | 124 // producer or |*num_bytes| is not a multiple of the data pipe's element |
| 125 // size). | 125 // size). |
| 126 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been | 126 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been |
| 127 // closed. | 127 // closed. |
| 128 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has | 128 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |
| 129 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data | 129 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data |
| 130 // (specified by |*num_bytes|) could not be written. | 130 // (specified by |*num_bytes|) could not be written. |
| 131 // |MOJO_RESULT_BUSY| if there is a two-phase write ongoing with | 131 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
| 132 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been | 132 // some transaction (that, e.g., may result in it being invalidated, such |
| 133 // as being sent in a message), or if there is a two-phase write ongoing |
| 134 // with |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been |
| 133 // called, but not yet the matching |MojoEndWriteData()|). | 135 // called, but not yet the matching |MojoEndWriteData()|). |
| 134 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the | 136 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the |
| 135 // consumer is still open) and |flags| does *not* have | 137 // consumer is still open) and |flags| does *not* have |
| 136 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. | 138 // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. |
| 137 // | 139 // |
| 138 // TODO(vtl): Should there be a way of querying how much data can be written? | 140 // TODO(vtl): Should there be a way of querying how much data can be written? |
| 139 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, // In. | 141 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, // In. |
| 140 const void* MOJO_RESTRICT elements, // In. | 142 const void* MOJO_RESTRICT elements, // In. |
| 141 uint32_t* MOJO_RESTRICT num_bytes, // In/out. | 143 uint32_t* MOJO_RESTRICT num_bytes, // In/out. |
| 142 MojoWriteDataFlags flags); // In. | 144 MojoWriteDataFlags flags); // In. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 156 // specify the amount written and to complete the two-phase write. | 158 // specify the amount written and to complete the two-phase write. |
| 157 // |MojoEndWriteData()| need not be called for other return values. | 159 // |MojoEndWriteData()| need not be called for other return values. |
| 158 // | 160 // |
| 159 // Returns: | 161 // Returns: |
| 160 // |MOJO_RESULT_OK| on success. | 162 // |MOJO_RESULT_OK| on success. |
| 161 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 163 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 162 // |data_pipe_producer_handle| is not a handle to a data pipe producer or | 164 // |data_pipe_producer_handle| is not a handle to a data pipe producer or |
| 163 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set). | 165 // flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set). |
| 164 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been | 166 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been |
| 165 // closed. | 167 // closed. |
| 166 // |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with | 168 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
| 167 // |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been | 169 // some transaction (that, e.g., may result in it being invalidated, such |
| 168 // called, but not yet the matching |MojoEndWriteData()|). | 170 // as being sent in a message), or if there is already a two-phase write |
| 171 // ongoing with |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| |
| 172 // has been called, but not yet the matching |MojoEndWriteData()|). |
| 169 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the | 173 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the |
| 170 // consumer is still open). | 174 // consumer is still open). |
| 171 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, // In. | 175 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, // In. |
| 172 void** MOJO_RESTRICT buffer, // Out. | 176 void** MOJO_RESTRICT buffer, // Out. |
| 173 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. | 177 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. |
| 174 MojoWriteDataFlags flags); // In. | 178 MojoWriteDataFlags flags); // In. |
| 175 | 179 |
| 176 // |MojoEndWriteData()|: Ends a two-phase write to the data pipe producer given | 180 // |MojoEndWriteData()|: Ends a two-phase write to the data pipe producer given |
| 177 // by |data_pipe_producer_handle| that was begun by a call to | 181 // by |data_pipe_producer_handle| that was begun by a call to |
| 178 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should | 182 // |MojoBeginWriteData()| on the same handle. |num_bytes_written| should |
| 179 // indicate the amount of data actually written; it must be less than or equal | 183 // indicate the amount of data actually written; it must be less than or equal |
| 180 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must | 184 // to the value of |*buffer_num_bytes| output by |MojoBeginWriteData()| and must |
| 181 // be a multiple of the element size. The buffer given by |*buffer| from | 185 // be a multiple of the element size. The buffer given by |*buffer| from |
| 182 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written| | 186 // |MojoBeginWriteData()| must have been filled with exactly |num_bytes_written| |
| 183 // bytes of data. | 187 // bytes of data. |
| 184 // | 188 // |
| 185 // On failure, the two-phase write (if any) is ended (so the handle may become | 189 // On failure, the two-phase write (if any) is ended (so the handle may become |
| 186 // writable again, if there's space available) but no data written to |*buffer| | 190 // writable again, if there's space available) but no data written to |*buffer| |
| 187 // is "put into" the data pipe. | 191 // is "put into" the data pipe. |
| 188 // | 192 // |
| 189 // Returns: | 193 // Returns: |
| 190 // |MOJO_RESULT_OK| on success. | 194 // |MOJO_RESULT_OK| on success. |
| 191 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 195 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 192 // |data_pipe_producer_handle| is not a handle to a data pipe producer or | 196 // |data_pipe_producer_handle| is not a handle to a data pipe producer or |
| 193 // |num_bytes_written| is invalid (greater than the maximum value provided | 197 // |num_bytes_written| is invalid (greater than the maximum value provided |
| 194 // by |MojoBeginWriteData()| or not a multiple of the element size). | 198 // by |MojoBeginWriteData()| or not a multiple of the element size). |
| 195 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a | 199 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a |
| 196 // two-phase write (e.g., |MojoBeginWriteData()| was not called or | 200 // two-phase write (e.g., |MojoBeginWriteData()| was not called or |
| 197 // |MojoEndWriteData()| has already been called). | 201 // |MojoEndWriteData()| has already been called). |
| 202 // |MOJO_RESULT_BUSY| if |data_pipe_producer_handle| is currently in use in |
| 203 // some transaction (that, e.g., may result in it being invalidated, such |
| 204 // as being sent in a message). |
| 198 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, // In. | 205 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, // In. |
| 199 uint32_t num_bytes_written); // In. | 206 uint32_t num_bytes_written); // In. |
| 200 | 207 |
| 201 // |MojoReadData()|: Reads data from the data pipe consumer given by | 208 // |MojoReadData()|: Reads data from the data pipe consumer given by |
| 202 // |data_pipe_consumer_handle|. May also be used to discard data or query the | 209 // |data_pipe_consumer_handle|. May also be used to discard data or query the |
| 203 // amount of data available. | 210 // amount of data available. |
| 204 // | 211 // |
| 205 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor | 212 // If |flags| has neither |MOJO_READ_DATA_FLAG_DISCARD| nor |
| 206 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which | 213 // |MOJO_READ_DATA_FLAG_QUERY| set, this tries to read up to |*num_bytes| (which |
| 207 // must be a multiple of the data pipe's element size) bytes of data to | 214 // must be a multiple of the data pipe's element size) bytes of data to |
| (...skipping 22 matching lines...) Expand all Loading... |
| 230 // operations). | 237 // operations). |
| 231 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 238 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 232 // |data_pipe_consumer_handle| is invalid, the combination of flags in | 239 // |data_pipe_consumer_handle| is invalid, the combination of flags in |
| 233 // |flags| is invalid, etc.). | 240 // |flags| is invalid, etc.). |
| 234 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been | 241 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been |
| 235 // closed and data (or the required amount of data) was not available to | 242 // closed and data (or the required amount of data) was not available to |
| 236 // be read or discarded. | 243 // be read or discarded. |
| 237 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| | 244 // |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| |
| 238 // set and the required amount of data is not available to be read or | 245 // set and the required amount of data is not available to be read or |
| 239 // discarded (and the producer is still open). | 246 // discarded (and the producer is still open). |
| 240 // |MOJO_RESULT_BUSY| if there is a two-phase read ongoing with | 247 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
| 241 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been | 248 // some transaction (that, e.g., may result in it being invalidated, such |
| 249 // as being sent in a message), or if there is a two-phase read ongoing |
| 250 // with |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been |
| 242 // called, but not yet the matching |MojoEndReadData()|). | 251 // called, but not yet the matching |MojoEndReadData()|). |
| 243 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and | 252 // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and |
| 244 // the producer is still open) and |flags| does *not* have | 253 // the producer is still open) and |flags| does *not* have |
| 245 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. | 254 // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. |
| 246 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, // In. | 255 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, // In. |
| 247 void* MOJO_RESTRICT elements, // Out. | 256 void* MOJO_RESTRICT elements, // Out. |
| 248 uint32_t* MOJO_RESTRICT num_bytes, // In/out. | 257 uint32_t* MOJO_RESTRICT num_bytes, // In/out. |
| 249 MojoReadDataFlags flags); // In. | 258 MojoReadDataFlags flags); // In. |
| 250 | 259 |
| 251 // |MojoBeginReadData()|: Begins a two-phase read from the data pipe consumer | 260 // |MojoBeginReadData()|: Begins a two-phase read from the data pipe consumer |
| (...skipping 10 matching lines...) Expand all Loading... |
| 262 // |MojoEndReadData()| to specify the amount read and to complete the two-phase | 271 // |MojoEndReadData()| to specify the amount read and to complete the two-phase |
| 263 // read. | 272 // read. |
| 264 // | 273 // |
| 265 // Returns: | 274 // Returns: |
| 266 // |MOJO_RESULT_OK| on success. | 275 // |MOJO_RESULT_OK| on success. |
| 267 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 276 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 268 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer, | 277 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer, |
| 269 // or |flags| has invalid flags set). | 278 // or |flags| has invalid flags set). |
| 270 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been | 279 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been |
| 271 // closed. | 280 // closed. |
| 272 // |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with | 281 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
| 273 // |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been | 282 // some transaction (that, e.g., may result in it being invalidated, such |
| 274 // called, but not yet the matching |MojoEndReadData()|). | 283 // as being sent in a message), or if there is already a two-phase read |
| 284 // ongoing with |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| |
| 285 // has been called, but not yet the matching |MojoEndReadData()|). |
| 275 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the | 286 // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the |
| 276 // producer is still open). | 287 // producer is still open). |
| 277 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, // In. | 288 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, // In. |
| 278 const void** MOJO_RESTRICT buffer, // Out. | 289 const void** MOJO_RESTRICT buffer, // Out. |
| 279 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. | 290 uint32_t* MOJO_RESTRICT buffer_num_bytes, // Out. |
| 280 MojoReadDataFlags flags); // In. | 291 MojoReadDataFlags flags); // In. |
| 281 | 292 |
| 282 // |MojoEndReadData()|: Ends a two-phase read from the data pipe consumer given | 293 // |MojoEndReadData()|: Ends a two-phase read from the data pipe consumer given |
| 283 // by |data_pipe_consumer_handle| that was begun by a call to | 294 // by |data_pipe_consumer_handle| that was begun by a call to |
| 284 // |MojoBeginReadData()| on the same handle. |num_bytes_read| should indicate | 295 // |MojoBeginReadData()| on the same handle. |num_bytes_read| should indicate |
| 285 // the amount of data actually read; it must be less than or equal to the value | 296 // the amount of data actually read; it must be less than or equal to the value |
| 286 // of |*buffer_num_bytes| output by |MojoBeginReadData()| and must be a multiple | 297 // of |*buffer_num_bytes| output by |MojoBeginReadData()| and must be a multiple |
| 287 // of the element size. | 298 // of the element size. |
| 288 // | 299 // |
| 289 // On failure, the two-phase read (if any) is ended (so the handle may become | 300 // On failure, the two-phase read (if any) is ended (so the handle may become |
| 290 // readable again) but no data is "removed" from the data pipe. | 301 // readable again) but no data is "removed" from the data pipe. |
| 291 // | 302 // |
| 292 // Returns: | 303 // Returns: |
| 293 // |MOJO_RESULT_OK| on success. | 304 // |MOJO_RESULT_OK| on success. |
| 294 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 305 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 295 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or | 306 // |data_pipe_consumer_handle| is not a handle to a data pipe consumer or |
| 296 // |num_bytes_written| is greater than the maximum value provided by | 307 // |num_bytes_written| is greater than the maximum value provided by |
| 297 // |MojoBeginReadData()| or not a multiple of the element size). | 308 // |MojoBeginReadData()| or not a multiple of the element size). |
| 298 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a | 309 // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a |
| 299 // two-phase read (e.g., |MojoBeginReadData()| was not called or | 310 // two-phase read (e.g., |MojoBeginReadData()| was not called or |
| 300 // |MojoEndReadData()| has already been called). | 311 // |MojoEndReadData()| has already been called). |
| 312 // |MOJO_RESULT_BUSY| if |data_pipe_consumer_handle| is currently in use in |
| 313 // some transaction (that, e.g., may result in it being invalidated, such |
| 314 // as being sent in a message). |
| 301 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, // In. | 315 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, // In. |
| 302 uint32_t num_bytes_read); // In. | 316 uint32_t num_bytes_read); // In. |
| 303 | 317 |
| 304 MOJO_END_EXTERN_C | 318 MOJO_END_EXTERN_C |
| 305 | 319 |
| 306 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ | 320 #endif // MOJO_PUBLIC_C_SYSTEM_DATA_PIPE_H_ |
| OLD | NEW |