Chromium Code Reviews| 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 message pipes. | 5 // This file contains types/constants and functions specific to message 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_MESSAGE_PIPE_H_ | 9 #ifndef MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ |
| 10 #define MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ | 10 #define MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 typedef uint32_t MojoReadMessageFlags; | 72 typedef uint32_t MojoReadMessageFlags; |
| 73 | 73 |
| 74 #ifdef __cplusplus | 74 #ifdef __cplusplus |
| 75 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0; | 75 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0; |
| 76 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD = 1 << 0; | 76 const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD = 1 << 0; |
| 77 #else | 77 #else |
| 78 #define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags)0) | 78 #define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags)0) |
| 79 #define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags)1 << 0) | 79 #define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags)1 << 0) |
| 80 #endif | 80 #endif |
| 81 | 81 |
| 82 // |MojoCreateMessageFlags|: Used to specify different options for | |
| 83 // |MojoCreateMessage()|. | |
| 84 // |MOJO_CREATE_MESSAGE_FLAG_NONE| - No flags; default mode. | |
| 85 | |
| 86 typedef uint32_t MojoCreateMessageFlags; | |
| 87 | |
| 88 #ifdef __cplusplus | |
| 89 const MojoCreateMessageFlags MOJO_CREATE_MESSAGE_FLAG_NONE = 0; | |
| 90 #else | |
| 91 #define MOJO_CREATE_MESSAGE_FLAG_NONE ((MojoCreateMessageFlags)0) | |
| 92 #endif | |
| 93 | |
| 82 #ifdef __cplusplus | 94 #ifdef __cplusplus |
| 83 extern "C" { | 95 extern "C" { |
| 84 #endif | 96 #endif |
| 85 | 97 |
| 86 // Note: See the comment in functions.h about the meaning of the "optional" | 98 // Note: See the comment in functions.h about the meaning of the "optional" |
| 87 // label for pointer parameters. | 99 // label for pointer parameters. |
| 88 | 100 |
| 89 // Creates a message pipe, which is a bidirectional communication channel for | 101 // Creates a message pipe, which is a bidirectional communication channel for |
| 90 // framed data (i.e., messages). Messages can contain plain data and/or Mojo | 102 // framed data (i.e., messages). Messages can contain plain data and/or Mojo |
| 91 // handles. | 103 // handles. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 110 // with message data specified by |bytes| of size |num_bytes| and attached | 122 // with message data specified by |bytes| of size |num_bytes| and attached |
| 111 // handles specified by |handles| of count |num_handles|, and options specified | 123 // handles specified by |handles| of count |num_handles|, and options specified |
| 112 // by |flags|. If there is no message data, |bytes| may be null, in which case | 124 // by |flags|. If there is no message data, |bytes| may be null, in which case |
| 113 // |num_bytes| must be zero. If there are no attached handles, |handles| may be | 125 // |num_bytes| must be zero. If there are no attached handles, |handles| may be |
| 114 // null, in which case |num_handles| must be zero. | 126 // null, in which case |num_handles| must be zero. |
| 115 // | 127 // |
| 116 // If handles are attached, on success the handles will no longer be valid (the | 128 // If handles are attached, on success the handles will no longer be valid (the |
| 117 // receiver will receive equivalent, but logically different, handles). Handles | 129 // receiver will receive equivalent, but logically different, handles). Handles |
| 118 // to be sent should not be in simultaneous use (e.g., on another thread). | 130 // to be sent should not be in simultaneous use (e.g., on another thread). |
| 119 // | 131 // |
| 132 // DEPRECATED: This function will be removed. Use |MojoWriteMessageNew()|. | |
|
Anand Mistry (off Chromium)
2016/04/19 12:57:36
I'd prefer if these weren't marked as deprecated j
Ken Rockot(use gerrit already)
2016/04/19 18:11:25
OK - Removed DEPRECATED notices and TODOs for now.
| |
| 133 // | |
| 120 // Returns: | 134 // Returns: |
| 121 // |MOJO_RESULT_OK| on success (i.e., the message was enqueued). | 135 // |MOJO_RESULT_OK| on success (i.e., the message was enqueued). |
| 122 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if | 136 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if |
| 123 // |message_pipe_handle| is not a valid handle, or some of the | 137 // |message_pipe_handle| is not a valid handle, or some of the |
| 124 // requirements above are not satisfied). | 138 // requirements above are not satisfied). |
| 125 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if some system limit has been reached, or | 139 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if some system limit has been reached, or |
| 126 // the number of handles to send is too large (TODO(vtl): reconsider the | 140 // the number of handles to send is too large (TODO(vtl): reconsider the |
| 127 // latter case). | 141 // latter case). |
| 128 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | 142 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. |
| 129 // Note that closing an endpoint is not necessarily synchronous (e.g., | 143 // Note that closing an endpoint is not necessarily synchronous (e.g., |
| 130 // across processes), so this function may succeed even if the other | 144 // across processes), so this function may succeed even if the other |
| 131 // endpoint has been closed (in which case the message would be dropped). | 145 // endpoint has been closed (in which case the message would be dropped). |
| 132 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 146 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
| 133 // |MOJO_RESULT_BUSY| if some handle to be sent is currently in use. | 147 // |MOJO_RESULT_BUSY| if some handle to be sent is currently in use. |
| 134 // | 148 // |
| 135 // TODO(vtl): Add a notion of capacity for message pipes, and return | 149 // TODO(vtl): Add a notion of capacity for message pipes, and return |
| 136 // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. | 150 // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. |
| 137 MOJO_SYSTEM_EXPORT MojoResult | 151 MOJO_SYSTEM_EXPORT MojoResult |
| 138 MojoWriteMessage(MojoHandle message_pipe_handle, | 152 MojoWriteMessage(MojoHandle message_pipe_handle, |
| 139 const void* bytes, // Optional. | 153 const void* bytes, // Optional. |
| 140 uint32_t num_bytes, | 154 uint32_t num_bytes, |
| 141 const MojoHandle* handles, // Optional. | 155 const MojoHandle* handles, // Optional. |
| 142 uint32_t num_handles, | 156 uint32_t num_handles, |
| 143 MojoWriteMessageFlags flags); | 157 MojoWriteMessageFlags flags); |
| 144 | 158 |
| 159 // Writes a message to the message pipe endpoint given by |message_pipe_handle|. | |
| 160 // | |
| 161 // |message|: A message object created by |MojoCreateMessage()|. Ownership of | |
| 162 // the message is passed into Mojo. | |
| 163 // | |
| 164 // | |
| 165 // TODO(rockot/amistry): Rename this to |MojoWriteMessage()| once that API is | |
| 166 // no longer used in its current form. | |
| 167 // | |
| 168 // Returns results corresponding to |MojoWriteMessage()| above. | |
| 169 MOJO_SYSTEM_EXPORT MojoResult | |
| 170 MojoWriteMessageNew(MojoHandle message_pipe_handle, | |
| 171 void* message, | |
| 172 MojoWriteMessageFlags); | |
| 173 | |
| 145 // Reads the next message from a message pipe, or indicates the size of the | 174 // Reads the next message from a message pipe, or indicates the size of the |
| 146 // message if it cannot fit in the provided buffers. The message will be read | 175 // message if it cannot fit in the provided buffers. The message will be read |
| 147 // in its entirety or not at all; if it is not, it will remain enqueued unless | 176 // in its entirety or not at all; if it is not, it will remain enqueued unless |
| 148 // the |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| flag was passed. At most one | 177 // the |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| flag was passed. At most one |
| 149 // message will be consumed from the queue, and the return value will indicate | 178 // message will be consumed from the queue, and the return value will indicate |
| 150 // whether a message was successfully read. | 179 // whether a message was successfully read. |
| 151 // | 180 // |
| 152 // |num_bytes| and |num_handles| are optional in/out parameters that on input | 181 // |num_bytes| and |num_handles| are optional in/out parameters that on input |
| 153 // must be set to the sizes of the |bytes| and |handles| arrays, and on output | 182 // must be set to the sizes of the |bytes| and |handles| arrays, and on output |
| 154 // will be set to the actual number of bytes or handles contained in the | 183 // will be set to the actual number of bytes or handles contained in the |
| 155 // message (even if the message was not retrieved due to being too large). | 184 // message (even if the message was not retrieved due to being too large). |
| 156 // Either |num_bytes| or |num_handles| may be null if the message is not | 185 // Either |num_bytes| or |num_handles| may be null if the message is not |
| 157 // expected to contain the corresponding type of data, but such a call would | 186 // expected to contain the corresponding type of data, but such a call would |
| 158 // fail with |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message in fact did | 187 // fail with |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message in fact did |
| 159 // contain that type of data. | 188 // contain that type of data. |
| 160 // | 189 // |
| 161 // |bytes| and |handles| will receive the contents of the message, if it is | 190 // |bytes| and |handles| will receive the contents of the message, if it is |
| 162 // retrieved. Either or both may be null, in which case the corresponding size | 191 // retrieved. Either or both may be null, in which case the corresponding size |
| 163 // parameter(s) must also be set to zero or passed as null. | 192 // parameter(s) must also be set to zero or passed as null. |
| 164 // | 193 // |
| 194 // DEPRECATED: This function will be removed. Use |MojoReadMessageNew()|. | |
| 195 // | |
| 165 // Returns: | 196 // Returns: |
| 166 // |MOJO_RESULT_OK| on success (i.e., a message was actually read). | 197 // |MOJO_RESULT_OK| on success (i.e., a message was actually read). |
| 167 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid. | 198 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid. |
| 168 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | 199 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. |
| 169 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message was too large to fit in the | 200 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message was too large to fit in the |
| 170 // provided buffer(s). The message will have been left in the queue or | 201 // provided buffer(s). The message will have been left in the queue or |
| 171 // discarded, depending on flags. | 202 // discarded, depending on flags. |
| 172 // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. | 203 // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. |
| 173 // | 204 // |
| 174 // TODO(vtl): Reconsider the |MOJO_RESULT_RESOURCE_EXHAUSTED| error code; should | 205 // TODO(vtl): Reconsider the |MOJO_RESULT_RESOURCE_EXHAUSTED| error code; should |
| 175 // distinguish this from the hitting-system-limits case. | 206 // distinguish this from the hitting-system-limits case. |
| 176 MOJO_SYSTEM_EXPORT MojoResult | 207 MOJO_SYSTEM_EXPORT MojoResult |
| 177 MojoReadMessage(MojoHandle message_pipe_handle, | 208 MojoReadMessage(MojoHandle message_pipe_handle, |
| 178 void* bytes, // Optional out. | 209 void* bytes, // Optional out. |
| 179 uint32_t* num_bytes, // Optional in/out. | 210 uint32_t* num_bytes, // Optional in/out. |
| 180 MojoHandle* handles, // Optional out. | 211 MojoHandle* handles, // Optional out. |
| 181 uint32_t* num_handles, // Optional in/out. | 212 uint32_t* num_handles, // Optional in/out. |
| 182 MojoReadMessageFlags flags); | 213 MojoReadMessageFlags flags); |
| 183 | 214 |
| 215 // Reads the next message from a message pipe and returns an address to a | |
| 216 // message containing the message bytes. The returned message must eventually be | |
| 217 // freed using |MojoDestroyMessage()|. | |
| 218 // | |
| 219 // Message payload can be accessed using |MojoGetMessageBuffer()|. | |
| 220 // | |
| 221 // |message_pipe_handle|, |num_bytes|, |handles|, |num_handles|, and |flags| | |
| 222 // correspond to their use in |MojoReadMessage()| above, with the | |
| 223 // exception that |num_bytes| is only an output argument. | |
| 224 // |message| must be non-null unless |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| is | |
| 225 // set in flags. | |
| 226 // | |
| 227 // Return values correspond to the return values for |MojoReadMessage()| above. | |
| 228 // On success (MOJO_RESULT_OK), |*message| will contain the address of a | |
| 229 // message object which may be passed to |MojoGetMessageBuffer()| and/or | |
| 230 // |MojoDestroyMessage()|. | |
| 231 // | |
| 232 // TODO(rockot/amistry): Rename this to |MojoReadMessage()| once that API is no | |
| 233 // longer used in its current form. | |
| 234 MOJO_SYSTEM_EXPORT MojoResult | |
| 235 MojoReadMessageNew(MojoHandle message_pipe_handle, | |
| 236 void** message, // Optional out. | |
| 237 uint32_t* num_bytes, // Optional out. | |
| 238 MojoHandle* handles, // Optional out. | |
| 239 uint32_t* num_handles, // Optional in/out. | |
| 240 MojoReadMessageFlags flags); | |
| 241 | |
| 184 // Fuses two message pipe endpoints together. Given two pipes: | 242 // Fuses two message pipe endpoints together. Given two pipes: |
| 185 // | 243 // |
| 186 // A <-> B and C <-> D | 244 // A <-> B and C <-> D |
| 187 // | 245 // |
| 188 // Fusing handle B and handle C results in a single pipe: | 246 // Fusing handle B and handle C results in a single pipe: |
| 189 // | 247 // |
| 190 // A <-> D | 248 // A <-> D |
| 191 // | 249 // |
| 192 // Handles B and C are ALWAYS closed. Any unread messages at C will eventually | 250 // Handles B and C are ALWAYS closed. Any unread messages at C will eventually |
| 193 // be delivered to A, and any unread messages at B will eventually be delivered | 251 // be delivered to A, and any unread messages at B will eventually be delivered |
| 194 // to D. | 252 // to D. |
| 195 // | 253 // |
| 196 // NOTE: A handle may only be fused if it is an open message pipe handle which | 254 // NOTE: A handle may only be fused if it is an open message pipe handle which |
| 197 // has not been written to. | 255 // has not been written to. |
| 198 // | 256 // |
| 199 // Returns: | 257 // Returns: |
| 200 // |MOJO_RESULT_OK| on success. | 258 // |MOJO_RESULT_OK| on success. |
| 201 // |MOJO_RESULT_FAILED_PRECONDITION| if both handles were valid message pipe | 259 // |MOJO_RESULT_FAILED_PRECONDITION| if both handles were valid message pipe |
| 202 // handles but could not be merged (e.g. one of them has been written to). | 260 // handles but could not be merged (e.g. one of them has been written to). |
| 203 // |MOJO_INVALID_ARGUMENT| if either handle is not a fusable message pipe | 261 // |MOJO_INVALID_ARGUMENT| if either handle is not a fusable message pipe |
| 204 // handle. | 262 // handle. |
| 205 MOJO_SYSTEM_EXPORT MojoResult | 263 MOJO_SYSTEM_EXPORT MojoResult |
| 206 MojoFuseMessagePipes(MojoHandle handle0, MojoHandle handle1); | 264 MojoFuseMessagePipes(MojoHandle handle0, MojoHandle handle1); |
| 207 | 265 |
| 266 // Allocates a new message whose ownership may be passed to | |
| 267 // |MojoWriteMessageNew()|. Use |MojoGetMessageBuffer()| to retrieve the address | |
| 268 // of the mutable message payload. | |
| 269 // | |
| 270 // |num_bytes|: The size of the message payload in bytes. | |
| 271 // |handles|: An array of handles to transfer in the message. This takes | |
| 272 // ownership of and invalidates all contained handles. Must be null if and | |
| 273 // only if |num_handles| is 0. | |
| 274 // |num_handles|: The number of handles contained in |handles|. | |
| 275 // |flags|: Must be |MOJO_CREATE_MESSAGE_FLAG_NONE|. | |
| 276 // |message|: The address of a pointer to be filled with the new message's | |
| 277 // address. Must be non-null. | |
| 278 // | |
| 279 // Returns: | |
| 280 // |MOJO_RESULT_OK| if the message was successfully allocated. In this case | |
| 281 // |*message| will be populated with the address of an allocated message | |
| 282 // large enough to hold at least |num_bytes| contiguous bytes. | |
| 283 // |MOJO_RESULT_INVALID_ARGUMENT| if one or more handles in |handles| was | |
| 284 // invalid, or |handles| was null with a non-zero |num_handles|. | |
| 285 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if allocation failed because either | |
| 286 // |num_bytes| or |num_handles| exceeds an implementation-defined maximum. | |
| 287 // |MOJO_RESULT_BUSY| if one or more handles in |handles| cannot be sent at | |
| 288 // the time of this call. | |
| 289 // | |
| 290 // Only upon successful message allocation will all handles in |handles| be | |
| 291 // transferred into the message and invalidated. | |
| 292 MOJO_SYSTEM_EXPORT MojoResult | |
| 293 MojoCreateMessage(uint32_t num_bytes, | |
| 294 const MojoHandle* handles, | |
| 295 uint32_t num_handles, | |
| 296 MojoCreateMessageFlags flags, | |
| 297 void** message); // Out | |
|
Anand Mistry (off Chromium)
2016/04/19 12:57:36
Since you're not meant to directly read/write the
Ken Rockot(use gerrit already)
2016/04/19 18:11:25
Done.
| |
| 298 | |
| 299 // Destroys a message allocated by |MojoCreateMessage()| or | |
| 300 // |MojoReadMessageNew()|. | |
| 301 // | |
| 302 // |message|: The address of the message to destroy. This must correspond to a | |
| 303 // message previously created by |MojoCreateMessage()| or | |
| 304 // |MojoReadMessageNew()|. Note that if the message has already been passed | |
| 305 // to |MojoWriteMessageNew()| it should NOT also be destroyed with this API. | |
| 306 // | |
| 307 // Returns: | |
| 308 // |MOJO_RESULT_OK| if |message| was valid and has been destroyed. | |
| 309 // |MOJO_RESULT_INVALID_ARGUMENT| if |message| was not a valid message object. | |
| 310 MOJO_SYSTEM_EXPORT MojoResult MojoDestroyMessage(void* message); | |
|
Anand Mistry (off Chromium)
2016/04/19 12:57:36
nit: In my experience (mainly media APIs), buffer
Ken Rockot(use gerrit already)
2016/04/19 18:11:25
I left the names unchanged for now. In general I t
Anand Mistry (off Chromium)
2016/04/21 12:19:42
I like Alloc/Free better than Create/Destroy. I do
Ken Rockot(use gerrit already)
2016/04/21 16:47:40
Done. MojoAllocMessage and MojoFreeMessage.
| |
| 311 | |
| 312 // Retrieves the address of mutable message bytes for a message created by | |
| 313 // either |MojoCreateMessage()| or |MojoReadMessageNew()|. | |
| 314 // | |
| 315 // |message|: The message object. | |
| 316 // | |
| 317 // Returns: | |
| 318 // |MOJO_RESULT_OK| if |message| is a valid message object. |*buffer| will | |
| 319 // be updated to point to mutable message bytes. | |
| 320 // |MOJO_RESULT_INVALID_ARGUMENT| if |message| is not a valid message object. | |
| 321 MOJO_SYSTEM_EXPORT MojoResult MojoGetMessageBuffer(void* message, | |
| 322 void** buffer); // Out | |
| 208 | 323 |
| 209 #ifdef __cplusplus | 324 #ifdef __cplusplus |
| 210 } // extern "C" | 325 } // extern "C" |
| 211 #endif | 326 #endif |
| 212 | 327 |
| 213 #endif // MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ | 328 #endif // MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ |
| OLD | NEW |