| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 MOJO_BEGIN_EXTERN_C | 57 MOJO_BEGIN_EXTERN_C |
| 58 | 58 |
| 59 // |MojoCreateMessagePipe()|: Creates a message pipe, which is a bidirectional | 59 // |MojoCreateMessagePipe()|: Creates a message pipe, which is a bidirectional |
| 60 // communication channel for framed data (i.e., messages). Messages can contain | 60 // communication channel for framed data (i.e., messages). Messages can contain |
| 61 // plain data and/or Mojo handles. | 61 // plain data and/or Mojo handles. |
| 62 // | 62 // |
| 63 // |options| may be set to null for a message pipe with the default options. | 63 // |options| may be set to null for a message pipe with the default options. |
| 64 // | 64 // |
| 65 // On success, |*message_pipe_handle0| and |*message_pipe_handle1| are set to | 65 // On success, |*message_pipe_handle0| and |*message_pipe_handle1| are set to |
| 66 // handles for the two endpoints (ports) for the message pipe. | 66 // handles for the two endpoints (ports) for the message pipe. Both handles have |
| 67 // (at least) the following rights: |MOJO_HANDLE_RIGHT_TRANSFER|, |
| 68 // |MOJO_HANDLE_RIGHT_READ|, |MOJO_HANDLE_RIGHT_WRITE|, |
| 69 // |MOJO_HANDLE_RIGHT_GET_OPTIONS|, and |MOJO_HANDLE_RIGHT_SET_OPTIONS|. |
| 67 // | 70 // |
| 68 // Returns: | 71 // Returns: |
| 69 // |MOJO_RESULT_OK| on success. | 72 // |MOJO_RESULT_OK| on success. |
| 70 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 73 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
| 71 // |*options| is invalid). | 74 // |*options| is invalid). |
| 72 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | 75 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has |
| 73 // been reached. | 76 // been reached. |
| 74 MojoResult MojoCreateMessagePipe( | 77 MojoResult MojoCreateMessagePipe( |
| 75 const struct MojoCreateMessagePipeOptions* MOJO_RESTRICT | 78 const struct MojoCreateMessagePipeOptions* MOJO_RESTRICT |
| 76 options, // Optional in. | 79 options, // Optional in. |
| 77 MojoHandle* MOJO_RESTRICT message_pipe_handle0, // Out. | 80 MojoHandle* MOJO_RESTRICT message_pipe_handle0, // Out. |
| 78 MojoHandle* MOJO_RESTRICT message_pipe_handle1); // Out. | 81 MojoHandle* MOJO_RESTRICT message_pipe_handle1); // Out. |
| 79 | 82 |
| 80 // |MojoWriteMessage()|: Writes a message to the message pipe endpoint given by | 83 // |MojoWriteMessage()|: Writes a message to the message pipe endpoint given by |
| 81 // |message_pipe_handle|, with message data specified by |bytes| of size | 84 // |message_pipe_handle| (which must have the |MOJO_HANDLE_RIGHT_WRITE| right), |
| 82 // |num_bytes| and attached handles specified by |handles| of count | 85 // with message data specified by |bytes| of size |num_bytes| and attached |
| 83 // |num_handles|, and options specified by |flags|. If there is no message data, | 86 // handles specified by |handles| of count |num_handles|, and options specified |
| 84 // |bytes| may be null, in which case |num_bytes| must be zero. If there are no | 87 // by |flags|. If there is no message data, |bytes| may be null, in which case |
| 85 // attached handles, |handles| may be null, in which case |num_handles| must be | 88 // |num_bytes| must be zero. If there are no attached handles, |handles| may be |
| 86 // zero. | 89 // null, in which case |num_handles| must be zero. |
| 87 // | 90 // |
| 88 // If handles are attached, on success the handles will no longer be valid (the | 91 // If handles are attached, on success the handles will no longer be valid (the |
| 89 // receiver will receive equivalent, but logically different, handles). Handles | 92 // receiver will receive equivalent, but logically different, handles). Handles |
| 90 // to be sent should not be in simultaneous use (e.g., on another thread). | 93 // to be sent should not be in simultaneous use (e.g., on another thread). On |
| 94 // failure, any handles to be attached will remain valid. |
| 91 // | 95 // |
| 92 // Returns: | 96 // Returns: |
| 93 // |MOJO_RESULT_OK| on success (i.e., the message was enqueued). | 97 // |MOJO_RESULT_OK| on success (i.e., the message was enqueued). |
| 94 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if | 98 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if |
| 95 // |message_pipe_handle| is not a valid handle, or some of the | 99 // |message_pipe_handle| is not a valid handle, or some of the |
| 96 // requirements above are not satisfied). | 100 // requirements above are not satisfied). |
| 101 // |MOJO_RESULT_PERMISSION_DENIED| if |message_pipe_handle| does not have the |
| 102 // |MOJO_HANDLE_RIGHT_WRITE| right. |
| 97 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if some system limit has been reached, or | 103 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if some system limit has been reached, or |
| 98 // the number of handles to send is too large (TODO(vtl): reconsider the | 104 // the number of handles to send is too large (TODO(vtl): reconsider the |
| 99 // latter case). | 105 // latter case). |
| 100 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | 106 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. |
| 101 // Note that closing an endpoint is not necessarily synchronous (e.g., | 107 // Note that closing an endpoint is not necessarily synchronous (e.g., |
| 102 // across processes), so this function may succeed even if the other | 108 // across processes), so this function may succeed even if the other |
| 103 // endpoint has been closed (in which case the message would be dropped). | 109 // endpoint has been closed (in which case the message would be dropped). |
| 104 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 110 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
| 105 // |MOJO_RESULT_BUSY| if |message_pipe_handle| is currently in use in some | 111 // |MOJO_RESULT_BUSY| if |message_pipe_handle| is currently in use in some |
| 106 // transaction (that, e.g., may result in it being invalidated, such as | 112 // transaction (that, e.g., may result in it being invalidated, such as |
| 107 // being sent in a message), or if some handle to be sent is currently in | 113 // being sent in a message), or if some handle to be sent is currently in |
| 108 // use. | 114 // use. |
| 109 // | 115 // |
| 110 // TODO(vtl): Add a notion of capacity for message pipes, and return | 116 // TODO(vtl): Add a notion of capacity for message pipes, and return |
| 111 // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. | 117 // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. |
| 112 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, // In. | 118 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, // In. |
| 113 const void* bytes, // Optional in. | 119 const void* bytes, // Optional in. |
| 114 uint32_t num_bytes, // In. | 120 uint32_t num_bytes, // In. |
| 115 const MojoHandle* handles, // Optional in. | 121 const MojoHandle* handles, // Optional in. |
| 116 uint32_t num_handles, // In. | 122 uint32_t num_handles, // In. |
| 117 MojoWriteMessageFlags flags); // In. | 123 MojoWriteMessageFlags flags); // In. |
| 118 | 124 |
| 119 // |MojoReadMessage()|: Reads the next message from a message pipe, or indicates | 125 // |MojoReadMessage()|: Reads the next message from the message pipe endpoint |
| 120 // the size of the message if it cannot fit in the provided buffers. The message | 126 // given by |message_pipe_handle| (which must have the |MOJO_HANDLE_RIGHT_READ| |
| 121 // will be read in its entirety or not at all; if it is not, it will remain | 127 // right) or indicates the size of the message if it cannot fit in the provided |
| 122 // enqueued unless the |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| flag was passed. At | 128 // buffers. The message will be read in its entirety or not at all; if it is |
| 123 // most one message will be consumed from the queue, and the return value will | 129 // not, it will remain enqueued unless the |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| |
| 124 // indicate whether a message was successfully read. | 130 // flag was passed. At most one message will be consumed from the queue, and the |
| 131 // return value will indicate whether a message was successfully read. |
| 125 // | 132 // |
| 126 // |num_bytes| and |num_handles| are optional in/out parameters that on input | 133 // |num_bytes| and |num_handles| are optional in/out parameters that on input |
| 127 // must be set to the sizes of the |bytes| and |handles| arrays, and on output | 134 // must be set to the sizes of the |bytes| and |handles| arrays, and on output |
| 128 // will be set to the actual number of bytes or handles contained in the | 135 // will be set to the actual number of bytes or handles contained in the |
| 129 // message (even if the message was not retrieved due to being too large). | 136 // message (even if the message was not retrieved due to being too large). |
| 130 // Either |num_bytes| or |num_handles| may be null if the message is not | 137 // Either |num_bytes| or |num_handles| may be null if the message is not |
| 131 // expected to contain the corresponding type of data, but such a call would | 138 // expected to contain the corresponding type of data, but such a call would |
| 132 // fail with |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message in fact did | 139 // fail with |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message in fact did |
| 133 // contain that type of data. | 140 // contain that type of data. |
| 134 // | 141 // |
| 135 // |bytes| and |handles| will receive the contents of the message, if it is | 142 // |bytes| and |handles| will receive the contents of the message, if it is |
| 136 // retrieved. Either or both may be null, in which case the corresponding size | 143 // retrieved. Either or both may be null, in which case the corresponding size |
| 137 // parameter(s) must also be set to zero or passed as null. | 144 // parameter(s) must also be set to zero or passed as null. |
| 138 // | 145 // |
| 139 // Returns: | 146 // Returns: |
| 140 // |MOJO_RESULT_OK| on success (i.e., a message was actually read). | 147 // |MOJO_RESULT_OK| on success (i.e., a message was actually read). |
| 141 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid. | 148 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid. |
| 142 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | 149 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. |
| 150 // |MOJO_RESULT_PERMISSION_DENIED| if |message_pipe_handle| does not have the |
| 151 // |MOJO_HANDLE_RIGHT_READ| right. |
| 143 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message was too large to fit in the | 152 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message was too large to fit in the |
| 144 // provided buffer(s). The message will have been left in the queue or | 153 // provided buffer(s). The message will have been left in the queue or |
| 145 // discarded, depending on flags. | 154 // discarded, depending on flags. |
| 146 // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. | 155 // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. |
| 147 // |MOJO_RESULT_BUSY| if |message_pipe_handle| is currently in use in some | 156 // |MOJO_RESULT_BUSY| if |message_pipe_handle| is currently in use in some |
| 148 // transaction (that, e.g., may result in it being invalidated, such as | 157 // transaction (that, e.g., may result in it being invalidated, such as |
| 149 // being sent in a message). | 158 // being sent in a message). |
| 150 // | 159 // |
| 151 // TODO(vtl): Reconsider the |MOJO_RESULT_RESOURCE_EXHAUSTED| error code; should | 160 // TODO(vtl): Reconsider the |MOJO_RESULT_RESOURCE_EXHAUSTED| error code; should |
| 152 // distinguish this from the hitting-system-limits case. | 161 // distinguish this from the hitting-system-limits case. |
| 153 MojoResult MojoReadMessage( | 162 MojoResult MojoReadMessage( |
| 154 MojoHandle message_pipe_handle, // In. | 163 MojoHandle message_pipe_handle, // In. |
| 155 void* MOJO_RESTRICT bytes, // Optional out. | 164 void* MOJO_RESTRICT bytes, // Optional out. |
| 156 uint32_t* MOJO_RESTRICT num_bytes, // Optional in/out. | 165 uint32_t* MOJO_RESTRICT num_bytes, // Optional in/out. |
| 157 MojoHandle* MOJO_RESTRICT handles, // Optional out. | 166 MojoHandle* MOJO_RESTRICT handles, // Optional out. |
| 158 uint32_t* MOJO_RESTRICT num_handles, // Optional in/out. | 167 uint32_t* MOJO_RESTRICT num_handles, // Optional in/out. |
| 159 MojoReadMessageFlags flags); // In. | 168 MojoReadMessageFlags flags); // In. |
| 160 | 169 |
| 161 MOJO_END_EXTERN_C | 170 MOJO_END_EXTERN_C |
| 162 | 171 |
| 163 #endif // MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ | 172 #endif // MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ |
| OLD | NEW |