1 /* 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.
7 * This file defines the <code>PPB_UDPSocket</code> interface.
15 [channel
=dev
] M43
= 1.2
19 * Option names used by <code>SetOption()</code>.
22 enum PP_UDPSocket_Option
{
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>.
28 PP_UDPSOCKET_OPTION_ADDRESS_REUSE
= 0,
31 * Allows sending and receiving packets to and from broadcast addresses.
32 * Value's type should be <code>PP_VARTYPE_BOOL</code>.
33 * 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.
36 PP_UDPSOCKET_OPTION_BROADCAST
= 1,
39 * Specifies the total per-socket buffer space reserved for sends. Value's
40 * type should be <code>PP_VARTYPE_INT32</code>.
41 * 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
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.
49 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE
= 2,
52 * Specifies the total per-socket buffer space reserved for receives. Value's
53 * type should be <code>PP_VARTYPE_INT32</code>.
54 * 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
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.
62 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE
= 3,
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>.
70 * This is only supported in version 1.2 of the API (Chrome 43) and later.
72 PP_UDPSOCKET_OPTION_MULTICAST_LOOP
= 4,
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>.
81 * This is only supported in version 1.2 of the API (Chrome 43) and later.
83 PP_UDPSOCKET_OPTION_MULTICAST_TTL
= 5
87 * The <code>PPB_UDPSocket</code> interface provides UDP socket operations.
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
95 interface PPB_UDPSocket
{
97 * Creates a UDP socket resource.
99 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
102 * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0
105 PP_Resource Create
([in] PP_Instance instance
);
108 * Determines if a given resource is a UDP socket.
110 * @param[in] resource A <code>PP_Resource</code> to check.
112 * @return <code>PP_TRUE</code> if the input is a <code>PPB_UDPSocket</code>
113 * resource; <code>PP_FALSE</code> otherwise.
115 PP_Bool IsUDPSocket
([in] PP_Resource resource
);
118 * Binds the socket to the given address.
120 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
122 * @param[in] addr A <code>PPB_NetAddress</code> resource.
123 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
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.
131 int32_t Bind
([in] PP_Resource udp_socket
,
132 [in] PP_Resource addr
,
133 [in] PP_CompletionCallback
callback);
136 * Gets the address that the socket is bound to. The socket must be bound.
138 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
141 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
143 PP_Resource GetBoundAddress
([in] PP_Resource udp_socket
);
146 * Receives data from the socket and stores the source address. The socket
149 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
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.
154 * @param[out] addr A <code>PPB_NetAddress</code> resource to store the source
155 * address on success.
156 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
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>.
162 int32_t RecvFrom
([in] PP_Resource udp_socket
,
164 [in] int32_t num_bytes
,
165 [out] PP_Resource addr
,
166 [in] PP_CompletionCallback
callback);
169 * Sends data to a specific destination. The socket must be bound.
171 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
173 * @param[in] buffer The buffer containing the data to send.
174 * @param[in] num_bytes The number of bytes to send.
175 * @param[in] addr A <code>PPB_NetAddress</code> resource holding the
176 * destination address.
177 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
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.
184 * <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
188 int32_t SendTo
([in] PP_Resource udp_socket
,
190 [in] int32_t num_bytes
,
191 [in] PP_Resource addr
,
192 [in] PP_CompletionCallback
callback);
195 * 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.
201 * The socket is implicitly closed if it is destroyed, so you are not
202 * required to call this method.
204 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
207 void Close
([in] PP_Resource udp_socket
);
210 * Sets a socket option on the UDP socket.
211 * Please see the <code>PP_UDPSocket_Option</code> description for option
212 * names, value types and allowed values.
214 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
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
221 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
223 int32_t SetOption
([in] PP_Resource udp_socket
,
224 [in] PP_UDPSocket_Option name
,
226 [in] PP_CompletionCallback
callback);
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.
233 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
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
240 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
243 int32_t SetOption
([in] PP_Resource udp_socket
,
244 [in] PP_UDPSocket_Option name
,
246 [in] PP_CompletionCallback
callback);
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.
253 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
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
260 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
263 int32_t SetOption
([in] PP_Resource udp_socket
,
264 [in] PP_UDPSocket_Option name
,
266 [in] PP_CompletionCallback
callback);
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.
272 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
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
279 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
282 int32_t JoinGroup
([in] PP_Resource udp_socket
,
283 [in] PP_Resource group
,
284 [in] PP_CompletionCallback
callback);
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.
290 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
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
297 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
300 int32_t LeaveGroup
([in] PP_Resource udp_socket
,
301 [in] PP_Resource group
,
302 [in] PP_CompletionCallback
callback);