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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 // | 83 // |
84 // On success, |*message_pipe_handle0| and |*message_pipe_handle1| are set to | 84 // On success, |*message_pipe_handle0| and |*message_pipe_handle1| are set to |
85 // handles for the two endpoints (ports) for the message pipe. | 85 // handles for the two endpoints (ports) for the message pipe. |
86 // | 86 // |
87 // Returns: | 87 // Returns: |
88 // |MOJO_RESULT_OK| on success. | 88 // |MOJO_RESULT_OK| on success. |
89 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., | 89 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., |
90 // |*options| is invalid). | 90 // |*options| is invalid). |
91 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | 91 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has |
92 // been reached. | 92 // been reached. |
93 // | |
94 // TODO(vtl): Add an options struct pointer argument. | |
95 MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe( | 93 MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe( |
96 const struct MojoCreateMessagePipeOptions* options, // Optional. | 94 const struct MojoCreateMessagePipeOptions* options, // Optional. |
97 MojoHandle* message_pipe_handle0, // Out. | 95 MojoHandle* message_pipe_handle0, // Out. |
98 MojoHandle* message_pipe_handle1); // Out. | 96 MojoHandle* message_pipe_handle1); // Out. |
99 | 97 |
100 // Writes a message to the message pipe endpoint given by |message_pipe_handle|, | 98 // Writes a message to the message pipe endpoint given by |message_pipe_handle|, |
101 // with message data specified by |bytes| of size |num_bytes| and attached | 99 // with message data specified by |bytes| of size |num_bytes| and attached |
102 // handles specified by |handles| of count |num_handles|, and options specified | 100 // handles specified by |handles| of count |num_handles|, and options specified |
103 // by |flags|. If there is no message data, |bytes| may be null, in which case | 101 // by |flags|. If there is no message data, |bytes| may be null, in which case |
104 // |num_bytes| must be zero. If there are no attached handles, |handles| may be | 102 // |num_bytes| must be zero. If there are no attached handles, |handles| may be |
105 // null, in which case |num_handles| must be zero. | 103 // null, in which case |num_handles| must be zero. |
106 // | 104 // |
107 // If handles are attached, on success the handles will no longer be valid (the | 105 // If handles are attached, on success the handles will no longer be valid (the |
108 // receiver will receive equivalent, but logically different, handles). Handles | 106 // receiver will receive equivalent, but logically different, handles). Handles |
109 // to be sent should not be in simultaneous use (e.g., on another thread). | 107 // to be sent should not be in simultaneous use (e.g., on another thread). |
110 // | 108 // |
111 // Returns: | 109 // Returns: |
112 // |MOJO_RESULT_OK| on success (i.e., the message was enqueued). | 110 // |MOJO_RESULT_OK| on success (i.e., the message was enqueued). |
113 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if | 111 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g., if |
114 // |message_pipe_handle| is not a valid handle, or some of the | 112 // |message_pipe_handle| is not a valid handle, or some of the |
115 // requirements above are not satisfied). | 113 // requirements above are not satisfied). |
116 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if some system limit has been reached, or | 114 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if some system limit has been reached, or |
117 // the number of handles to send is too large (TODO(vtl): reconsider the | 115 // the number of handles to send is too large (TODO(vtl): reconsider the |
118 // latter case). | 116 // latter case). |
119 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | 117 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. |
120 // Note that closing an endpoint is not necessarily synchronous (e.g., | 118 // Note that closing an endpoint is not necessarily synchronous (e.g., |
121 // across processes), so this function may be succeed even if the other | 119 // across processes), so this function may succeed even if the other |
122 // endpoint has been closed (in which case the message would be dropped). | 120 // endpoint has been closed (in which case the message would be dropped). |
123 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. | 121 // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. |
124 // |MOJO_RESULT_BUSY| if some handle to be sent is currently in use. | 122 // |MOJO_RESULT_BUSY| if some handle to be sent is currently in use. |
125 // | 123 // |
126 // TODO(vtl): Add a notion of capacity for message pipes, and return | 124 // TODO(vtl): Add a notion of capacity for message pipes, and return |
127 // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. | 125 // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. |
128 MOJO_SYSTEM_EXPORT MojoResult | 126 MOJO_SYSTEM_EXPORT MojoResult |
129 MojoWriteMessage(MojoHandle message_pipe_handle, | 127 MojoWriteMessage(MojoHandle message_pipe_handle, |
130 const void* bytes, // Optional. | 128 const void* bytes, // Optional. |
131 uint32_t num_bytes, | 129 uint32_t num_bytes, |
132 const MojoHandle* handles, // Optional. | 130 const MojoHandle* handles, // Optional. |
133 uint32_t num_handles, | 131 uint32_t num_handles, |
134 MojoWriteMessageFlags flags); | 132 MojoWriteMessageFlags flags); |
135 | 133 |
136 // Reads a message from the message pipe endpoint given by | 134 // Reads the next message from a message pipe, or indicates the size of the |
137 // |message_pipe_handle|; also usable to query the size of the next message or | 135 // message if it cannot fit in the provided buffers. The message must be read in |
138 // discard the next message. |bytes|/|*num_bytes| indicate the buffer/buffer | 136 // its entirety or it will not be read at all. If the message is too large, it |
viettrungluu
2015/01/30 22:23:57
nit: one space after '.'
ggowan
2015/01/30 22:43:08
Done.
| |
139 // size to receive the message data (if any) and |handles|/|*num_handles| | 137 // will not be removed from the queue unless the |
140 // indicate the buffer/maximum handle count to receive the attached handles (if | 138 // |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| flag is passed. Either way, at most one |
141 // any). | 139 // message will be consumed from the queue with each call, and the return value |
140 // will indicate whether a message was successfully read. | |
142 // | 141 // |
143 // |num_bytes| and |num_handles| are optional "in-out" parameters. If non-null, | 142 // |num_bytes| and |num_handles| are in/out parameters that on input must be set |
viettrungluu
2015/01/30 22:23:57
You should probably say "optional in/out"; otherwi
ggowan
2015/01/30 22:43:08
Done.
| |
144 // on return |*num_bytes| and |*num_handles| will usually indicate the number | 143 // to the sizes of the |bytes| and |handles| arrays, and on output will be set |
145 // of bytes and number of attached handles in the "next" message, respectively, | 144 // to the actual number of bytes or handles contained in the message. Either |
viettrungluu
2015/01/30 22:23:57
...
ggowan
2015/01/30 22:43:08
Done.
| |
146 // whether that message was read or not. (If null, the number of bytes/handles | 145 // |num_bytes| or |num_handles| may be null if the message is not expected to |
147 // is treated as zero.) | 146 // contain the corresponding type of data, but such a call would fail with |
147 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message in fact did contain that type | |
148 // of data. | |
148 // | 149 // |
149 // If |bytes| is null, then |*num_bytes| must be zero, and similarly for | 150 // |bytes| and |handles| are output arrays that will receive the contents of the |
viettrungluu
2015/01/30 22:23:57
This paragraph is overly verbose.
ggowan
2015/01/30 22:43:08
Trimmed. I moved some of this into previous paragr
| |
150 // |handles| and |*num_handles|. | 151 // message. Either or both may be passed as null if the caller merely wants to |
151 // | 152 // find out the size of the next message before retrieving it, or if the message |
152 // Partial reads are NEVER done. Either a full read is done and |MOJO_RESULT_OK| | 153 // is not expected to contain the corresponding type of data. However, if that |
153 // returned, or the read is NOT done and |MOJO_RESULT_RESOURCE_EXHAUSTED| is | 154 // is done, the corresponding size parameter(s) must also be set to zero on |
154 // returned (if |MOJO_READ_MESSAGE_FLAG_MAY_DISCARD| was set, the message is | 155 // input or passed as null. |
155 // also discarded in this case). | |
156 // | 156 // |
157 // Returns: | 157 // Returns: |
158 // |MOJO_RESULT_OK| on success (i.e., a message was actually read). | 158 // |MOJO_RESULT_OK| on success (i.e., a message was actually read). |
159 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid. | 159 // |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid. |
160 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. | 160 // |MOJO_RESULT_FAILED_PRECONDITION| if the other endpoint has been closed. |
161 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if one of the buffers to receive the | 161 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if the message was too large to fit in the |
162 // message/attached handles (|bytes|/|*num_bytes| or | 162 // provided buffer(s). The message will have been left in the queue or |
163 // |handles|/|*num_handles|) was too small. (TODO(vtl): Reconsider this | 163 // discarded, depending on flags. |
164 // error code; should distinguish this from the hitting-system-limits | |
165 // case.) | |
166 // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. | 164 // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. |
165 // | |
166 // TODO(vtl): Reconsider the |MOJO_RESULT_RESOURCE_EXHAUSTED| error code; should | |
167 // distinguish this from the hitting-system-limits case. | |
167 MOJO_SYSTEM_EXPORT MojoResult | 168 MOJO_SYSTEM_EXPORT MojoResult |
168 MojoReadMessage(MojoHandle message_pipe_handle, | 169 MojoReadMessage(MojoHandle message_pipe_handle, |
169 void* bytes, // Optional out. | 170 void* bytes, // Optional out. |
170 uint32_t* num_bytes, // Optional in/out. | 171 uint32_t* num_bytes, // Optional in/out. |
171 MojoHandle* handles, // Optional out. | 172 MojoHandle* handles, // Optional out. |
172 uint32_t* num_handles, // Optional in/out. | 173 uint32_t* num_handles, // Optional in/out. |
173 MojoReadMessageFlags flags); | 174 MojoReadMessageFlags flags); |
174 | 175 |
175 #ifdef __cplusplus | 176 #ifdef __cplusplus |
176 } // extern "C" | 177 } // extern "C" |
177 #endif | 178 #endif |
178 | 179 |
179 #endif // MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ | 180 #endif // MOJO_PUBLIC_C_SYSTEM_MESSAGE_PIPE_H_ |
OLD | NEW |