blob: a9e7f84c22cffee5e6dc782a9b78124175a6226c [file] [log] [blame]
[email protected]31cb1472013-06-13 22:43:391/* Copyright 2013 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6/**
[email protected]8de13292013-06-24 06:04:397 * This file defines the <code>PPB_UDPSocket</code> interface.
[email protected]31cb1472013-06-13 22:43:398 */
9
eduardo.lima8171d462015-03-13 15:40:2110[generate_thunk]
11
[email protected]31cb1472013-06-13 22:43:3912label Chrome {
hidehikofd305c122014-12-11 06:01:4713 M29 = 1.0,
eduardo.lima8171d462015-03-13 15:40:2114 M41 = 1.1,
eduardo.lima7e4f2d12015-06-25 14:28:1615 M43 = 1.2
[email protected]31cb1472013-06-13 22:43:3916};
17
[email protected]a58eae872013-06-22 14:29:0218/**
19 * Option names used by <code>SetOption()</code>.
20 */
[email protected]31cb1472013-06-13 22:43:3921[assert_size(4)]
[email protected]8de13292013-06-24 06:04:3922enum PP_UDPSocket_Option {
[email protected]a58eae872013-06-22 14:29:0223 /**
24 * Allows the socket to share the local address to which it will be bound with
25 * other processes. Value's type should be <code>PP_VARTYPE_BOOL</code>.
26 * This option can only be set before calling <code>Bind()</code>.
27 */
[email protected]31cb1472013-06-13 22:43:3928 PP_UDPSOCKET_OPTION_ADDRESS_REUSE = 0,
29
[email protected]a58eae872013-06-22 14:29:0230 /**
31 * Allows sending and receiving packets to and from broadcast addresses.
32 * Value's type should be <code>PP_VARTYPE_BOOL</code>.
hidehikofd305c122014-12-11 06:01:4733 * On version 1.0, this option can only be set before calling
34 * <code>Bind()</code>. On version 1.1 or later, there is no such limitation.
[email protected]a58eae872013-06-22 14:29:0235 */
[email protected]31cb1472013-06-13 22:43:3936 PP_UDPSOCKET_OPTION_BROADCAST = 1,
37
[email protected]a58eae872013-06-22 14:29:0238 /**
39 * Specifies the total per-socket buffer space reserved for sends. Value's
40 * type should be <code>PP_VARTYPE_INT32</code>.
hidehikofd305c122014-12-11 06:01:4741 * On version 1.0, this option can only be set after a successful
42 * <code>Bind()</code> call. On version 1.1 or later, there is no such
43 * limitation.
[email protected]a58eae872013-06-22 14:29:0244 *
45 * Note: This is only treated as a hint for the browser to set the buffer
46 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
47 * guarantee it will conform to the size.
48 */
[email protected]31cb1472013-06-13 22:43:3949 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE = 2,
50
[email protected]a58eae872013-06-22 14:29:0251 /**
52 * Specifies the total per-socket buffer space reserved for receives. Value's
53 * type should be <code>PP_VARTYPE_INT32</code>.
hidehikofd305c122014-12-11 06:01:4754 * On version 1.0, this option can only be set after a successful
55 * <code>Bind()</code> call. On version 1.1 or later, there is no such
56 * limitation.
[email protected]a58eae872013-06-22 14:29:0257 *
58 * Note: This is only treated as a hint for the browser to set the buffer
59 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
60 * guarantee it will conform to the size.
61 */
eduardo.lima8171d462015-03-13 15:40:2162 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE = 3,
63
64 /**
65 * Specifies whether the packets sent from the host to the multicast group
66 * should be looped back to the host or not. Value's type should be
67 * <code>PP_VARTYPE_BOOL</code>.
68 * This option can only be set before calling <code>Bind()</code>.
69 *
70 * This is only supported in version 1.2 of the API (Chrome 43) and later.
71 */
72 PP_UDPSOCKET_OPTION_MULTICAST_LOOP = 4,
73
74 /**
75 * Specifies the time-to-live for packets sent to the multicast group. The
76 * value should be within 0 to 255 range. The default value is 1 and means
77 * that packets will not be routed beyond the local network. Value's type
78 * should be <code>PP_VARTYPE_INT32</code>.
79 * This option can only be set before calling <code>Bind()</code>.
80 *
81 * This is only supported in version 1.2 of the API (Chrome 43) and later.
82 */
83 PP_UDPSOCKET_OPTION_MULTICAST_TTL = 5
[email protected]31cb1472013-06-13 22:43:3984};
85
[email protected]a58eae872013-06-22 14:29:0286/**
[email protected]8de13292013-06-24 06:04:3987 * The <code>PPB_UDPSocket</code> interface provides UDP socket operations.
[email protected]a58eae872013-06-22 14:29:0288 *
89 * Permissions: Apps permission <code>socket</code> with subrule
90 * <code>udp-bind</code> is required for <code>Bind()</code>; subrule
91 * <code>udp-send-to</code> is required for <code>SendTo()</code>.
92 * For more details about network communication permissions, please see:
93 * http://developer.chrome.com/apps/app_network.html
94 */
[email protected]8de13292013-06-24 06:04:3995interface PPB_UDPSocket {
[email protected]31cb1472013-06-13 22:43:3996 /**
97 * Creates a UDP socket resource.
[email protected]a58eae872013-06-22 14:29:0298 *
99 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
100 * a module.
101 *
102 * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0
103 * on failure.
[email protected]31cb1472013-06-13 22:43:39104 */
105 PP_Resource Create([in] PP_Instance instance);
106
107 /**
108 * Determines if a given resource is a UDP socket.
[email protected]a58eae872013-06-22 14:29:02109 *
110 * @param[in] resource A <code>PP_Resource</code> to check.
111 *
[email protected]8de13292013-06-24 06:04:39112 * @return <code>PP_TRUE</code> if the input is a <code>PPB_UDPSocket</code>
113 * resource; <code>PP_FALSE</code> otherwise.
[email protected]31cb1472013-06-13 22:43:39114 */
115 PP_Bool IsUDPSocket([in] PP_Resource resource);
116
117 /**
[email protected]a58eae872013-06-22 14:29:02118 * Binds the socket to the given address.
119 *
120 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
121 * socket.
[email protected]ee517552013-06-22 20:07:50122 * @param[in] addr A <code>PPB_NetAddress</code> resource.
[email protected]a58eae872013-06-22 14:29:02123 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
124 * completion.
125 *
126 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
127 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
128 * required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be returned
129 * if the address is already in use.
[email protected]31cb1472013-06-13 22:43:39130 */
131 int32_t Bind([in] PP_Resource udp_socket,
132 [in] PP_Resource addr,
133 [in] PP_CompletionCallback callback);
134
135 /**
[email protected]a58eae872013-06-22 14:29:02136 * Gets the address that the socket is bound to. The socket must be bound.
137 *
138 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
139 * socket.
140 *
[email protected]ee517552013-06-22 20:07:50141 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
[email protected]31cb1472013-06-13 22:43:39142 */
143 PP_Resource GetBoundAddress([in] PP_Resource udp_socket);
144
145 /**
[email protected]a58eae872013-06-22 14:29:02146 * Receives data from the socket and stores the source address. The socket
147 * must be bound.
148 *
149 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
150 * socket.
151 * @param[out] buffer The buffer to store the received data on success. It
152 * must be at least as large as <code>num_bytes</code>.
153 * @param[in] num_bytes The number of bytes to receive.
[email protected]ee517552013-06-22 20:07:50154 * @param[out] addr A <code>PPB_NetAddress</code> resource to store the source
155 * address on success.
[email protected]a58eae872013-06-22 14:29:02156 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
157 * completion.
158 *
159 * @return A non-negative number on success to indicate how many bytes have
160 * been received; otherwise, an error code from <code>pp_errors.h</code>.
[email protected]31cb1472013-06-13 22:43:39161 */
162 int32_t RecvFrom([in] PP_Resource udp_socket,
163 [out] str_t buffer,
164 [in] int32_t num_bytes,
165 [out] PP_Resource addr,
166 [in] PP_CompletionCallback callback);
167
168 /**
[email protected]a58eae872013-06-22 14:29:02169 * Sends data to a specific destination. The socket must be bound.
170 *
171 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
172 * socket.
173 * @param[in] buffer The buffer containing the data to send.
174 * @param[in] num_bytes The number of bytes to send.
[email protected]ee517552013-06-22 20:07:50175 * @param[in] addr A <code>PPB_NetAddress</code> resource holding the
[email protected]a58eae872013-06-22 14:29:02176 * destination address.
177 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
178 * completion.
179 *
180 * @return A non-negative number on success to indicate how many bytes have
181 * been sent; otherwise, an error code from <code>pp_errors.h</code>.
182 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
183 * required permissions.
bbudgec76a0f92015-01-14 22:42:01184 * <code>PP_ERROR_INPROGRESS</code> will be returned if the socket is busy
185 * sending. The caller should wait until a pending send completes before
186 * retrying.
[email protected]31cb1472013-06-13 22:43:39187 */
188 int32_t SendTo([in] PP_Resource udp_socket,
189 [in] str_t buffer,
190 [in] int32_t num_bytes,
191 [in] PP_Resource addr,
192 [in] PP_CompletionCallback callback);
193
194 /**
[email protected]a58eae872013-06-22 14:29:02195 * Cancels all pending reads and writes, and closes the socket. Any pending
196 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if
197 * pending IO was interrupted. After a call to this method, no output
198 * parameters passed into previous <code>RecvFrom()</code> calls will be
199 * accessed. It is not valid to call <code>Bind()</code> again.
200 *
201 * The socket is implicitly closed if it is destroyed, so you are not
202 * required to call this method.
203 *
204 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
205 * socket.
[email protected]31cb1472013-06-13 22:43:39206 */
207 void Close([in] PP_Resource udp_socket);
208
209 /**
[email protected]a58eae872013-06-22 14:29:02210 * Sets a socket option on the UDP socket.
[email protected]8de13292013-06-24 06:04:39211 * Please see the <code>PP_UDPSocket_Option</code> description for option
[email protected]a58eae872013-06-22 14:29:02212 * names, value types and allowed values.
213 *
214 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
215 * socket.
216 * @param[in] name The option to set.
217 * @param[in] value The option value to set.
218 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
219 * completion.
220 *
221 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
[email protected]31cb1472013-06-13 22:43:39222 */
223 int32_t SetOption([in] PP_Resource udp_socket,
[email protected]8de13292013-06-24 06:04:39224 [in] PP_UDPSocket_Option name,
[email protected]31cb1472013-06-13 22:43:39225 [in] PP_Var value,
226 [in] PP_CompletionCallback callback);
hidehikofd305c122014-12-11 06:01:47227
228 /**
229 * Sets a socket option on the UDP socket.
230 * Please see the <code>PP_UDPSocket_Option</code> description for option
231 * names, value types and allowed values.
232 *
233 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
234 * socket.
235 * @param[in] name The option to set.
236 * @param[in] value The option value to set.
237 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
238 * completion.
239 *
240 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
241 */
242 [version=1.1]
243 int32_t SetOption([in] PP_Resource udp_socket,
244 [in] PP_UDPSocket_Option name,
245 [in] PP_Var value,
246 [in] PP_CompletionCallback callback);
eduardo.lima8171d462015-03-13 15:40:21247
248 /**
249 * Sets a socket option on the UDP socket.
250 * Please see the <code>PP_UDPSocket_Option</code> description for option
251 * names, value types and allowed values.
252 *
253 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
254 * socket.
255 * @param[in] name The option to set.
256 * @param[in] value The option value to set.
257 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
258 * completion.
259 *
260 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
261 */
262 [version=1.2]
263 int32_t SetOption([in] PP_Resource udp_socket,
264 [in] PP_UDPSocket_Option name,
265 [in] PP_Var value,
266 [in] PP_CompletionCallback callback);
267
268 /**
269 * Joins the multicast group with address specified by <code>group</code>
270 * parameter, which is expected to be a <code>PPB_NetAddress</code> object.
271 *
272 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
273 * socket.
274 * @param[in] group A <code>PP_Resource</code> corresponding to the network
275 * address of the multicast group.
276 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
277 * completion.
278 *
279 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
280 */
281 [version=1.2]
282 int32_t JoinGroup([in] PP_Resource udp_socket,
283 [in] PP_Resource group,
284 [in] PP_CompletionCallback callback);
285
286 /**
287 * Leaves the multicast group with address specified by <code>group</code>
288 * parameter, which is expected to be a <code>PPB_NetAddress</code> object.
289 *
290 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
291 * socket.
292 * @param[in] group A <code>PP_Resource</code> corresponding to the network
293 * address of the multicast group.
294 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
295 * completion.
296 *
297 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
298 */
299 [version=1.2]
300 int32_t LeaveGroup([in] PP_Resource udp_socket,
301 [in] PP_Resource group,
302 [in] PP_CompletionCallback callback);
[email protected]31cb1472013-06-13 22:43:39303};