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.
6 /* From ppb_udp_socket.idl modified Tue Mar 17 11:47:56 2015. */
8 #ifndef PPAPI_C_PPB_UDP_SOCKET_H_
9 #define PPAPI_C_PPB_UDP_SOCKET_H_
11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_macros.h"
15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/pp_stdint.h"
17 #include "ppapi/c/pp_var.h"
19 #define PPB_UDPSOCKET_INTERFACE_1_0 "PPB_UDPSocket;1.0"
20 #define PPB_UDPSOCKET_INTERFACE_1_1 "PPB_UDPSocket;1.1"
21 #define PPB_UDPSOCKET_INTERFACE_1_2 "PPB_UDPSocket;1.2"
22 #define PPB_UDPSOCKET_INTERFACE PPB_UDPSOCKET_INTERFACE_1_2
26 * This file defines the <code>PPB_UDPSocket</code> interface.
35 * Option names used by <code>SetOption()</code>.
39 * Allows the socket to share the local address to which it will be bound with
40 * other processes. Value's type should be <code>PP_VARTYPE_BOOL</code>.
41 * This option can only be set before calling <code>Bind()</code>.
43 PP_UDPSOCKET_OPTION_ADDRESS_REUSE
= 0,
45 * Allows sending and receiving packets to and from broadcast addresses.
46 * Value's type should be <code>PP_VARTYPE_BOOL</code>.
47 * On version 1.0, this option can only be set before calling
48 * <code>Bind()</code>. On version 1.1 or later, there is no such limitation.
50 PP_UDPSOCKET_OPTION_BROADCAST
= 1,
52 * Specifies the total per-socket buffer space reserved for sends. 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_SEND_BUFFER_SIZE
= 2,
64 * Specifies the total per-socket buffer space reserved for receives. Value's
65 * type should be <code>PP_VARTYPE_INT32</code>.
66 * On version 1.0, this option can only be set after a successful
67 * <code>Bind()</code> call. On version 1.1 or later, there is no such
70 * Note: This is only treated as a hint for the browser to set the buffer
71 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
72 * guarantee it will conform to the size.
74 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE
= 3,
76 * Specifies whether the packets sent from the host to the multicast group
77 * should be looped back to the host or not. Value's type should be
78 * <code>PP_VARTYPE_BOOL</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_LOOP
= 4,
85 * Specifies the time-to-live for packets sent to the multicast group. The
86 * value should be within 0 to 255 range. The default value is 1 and means
87 * that packets will not be routed beyond the local network. Value's type
88 * should be <code>PP_VARTYPE_INT32</code>.
89 * This option can only be set before calling <code>Bind()</code>.
91 * This is only supported in version 1.2 of the API (Chrome 43) and later.
93 PP_UDPSOCKET_OPTION_MULTICAST_TTL
= 5
94 } PP_UDPSocket_Option
;
95 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_UDPSocket_Option
, 4);
101 * @addtogroup Interfaces
105 * The <code>PPB_UDPSocket</code> interface provides UDP socket operations.
107 * Permissions: Apps permission <code>socket</code> with subrule
108 * <code>udp-bind</code> is required for <code>Bind()</code>; subrule
109 * <code>udp-send-to</code> is required for <code>SendTo()</code>.
110 * For more details about network communication permissions, please see:
111 * http://developer.chrome.com/apps/app_network.html
113 struct PPB_UDPSocket_1_2
{
115 * Creates a UDP socket resource.
117 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
120 * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0
123 PP_Resource (*Create
)(PP_Instance instance
);
125 * Determines if a given resource is a UDP socket.
127 * @param[in] resource A <code>PP_Resource</code> to check.
129 * @return <code>PP_TRUE</code> if the input is a <code>PPB_UDPSocket</code>
130 * resource; <code>PP_FALSE</code> otherwise.
132 PP_Bool (*IsUDPSocket
)(PP_Resource resource
);
134 * Binds the socket to the given address.
136 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
138 * @param[in] addr A <code>PPB_NetAddress</code> resource.
139 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
142 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
143 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
144 * required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be returned
145 * if the address is already in use.
147 int32_t (*Bind
)(PP_Resource udp_socket
,
149 struct PP_CompletionCallback callback
);
151 * Gets the address that the socket is bound to. The socket must be bound.
153 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
156 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
158 PP_Resource (*GetBoundAddress
)(PP_Resource udp_socket
);
160 * Receives data from the socket and stores the source address. The socket
163 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
165 * @param[out] buffer The buffer to store the received data on success. It
166 * must be at least as large as <code>num_bytes</code>.
167 * @param[in] num_bytes The number of bytes to receive.
168 * @param[out] addr A <code>PPB_NetAddress</code> resource to store the source
169 * address on success.
170 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
173 * @return A non-negative number on success to indicate how many bytes have
174 * been received; otherwise, an error code from <code>pp_errors.h</code>.
176 int32_t (*RecvFrom
)(PP_Resource udp_socket
,
180 struct PP_CompletionCallback callback
);
182 * Sends data to a specific destination. The socket must be bound.
184 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
186 * @param[in] buffer The buffer containing the data to send.
187 * @param[in] num_bytes The number of bytes to send.
188 * @param[in] addr A <code>PPB_NetAddress</code> resource holding the
189 * destination address.
190 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
193 * @return A non-negative number on success to indicate how many bytes have
194 * been sent; otherwise, an error code from <code>pp_errors.h</code>.
195 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
196 * required permissions.
197 * <code>PP_ERROR_INPROGRESS</code> will be returned if the socket is busy
198 * sending. The caller should wait until a pending send completes before
201 int32_t (*SendTo
)(PP_Resource udp_socket
,
205 struct PP_CompletionCallback callback
);
207 * Cancels all pending reads and writes, and closes the socket. Any pending
208 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if
209 * pending IO was interrupted. After a call to this method, no output
210 * parameters passed into previous <code>RecvFrom()</code> calls will be
211 * accessed. It is not valid to call <code>Bind()</code> again.
213 * The socket is implicitly closed if it is destroyed, so you are not
214 * required to call this method.
216 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
219 void (*Close
)(PP_Resource udp_socket
);
221 * Sets a socket option on the UDP socket.
222 * Please see the <code>PP_UDPSocket_Option</code> description for option
223 * names, value types and allowed values.
225 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
227 * @param[in] name The option to set.
228 * @param[in] value The option value to set.
229 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
232 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
234 int32_t (*SetOption
)(PP_Resource udp_socket
,
235 PP_UDPSocket_Option name
,
237 struct PP_CompletionCallback callback
);
239 * Joins the multicast group with address specified by <code>group</code>
240 * parameter, which is expected to be a <code>PPB_NetAddress</code> object.
242 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
244 * @param[in] group A <code>PP_Resource</code> corresponding to the network
245 * address of the multicast group.
246 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
249 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
251 int32_t (*JoinGroup
)(PP_Resource udp_socket
,
253 struct PP_CompletionCallback callback
);
255 * Leaves the multicast group with address specified by <code>group</code>
256 * parameter, which is expected to be a <code>PPB_NetAddress</code> object.
258 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
260 * @param[in] group A <code>PP_Resource</code> corresponding to the network
261 * address of the multicast group.
262 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
265 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
267 int32_t (*LeaveGroup
)(PP_Resource udp_socket
,
269 struct PP_CompletionCallback callback
);
272 typedef struct PPB_UDPSocket_1_2 PPB_UDPSocket
;
274 struct PPB_UDPSocket_1_0
{
275 PP_Resource (*Create
)(PP_Instance instance
);
276 PP_Bool (*IsUDPSocket
)(PP_Resource resource
);
277 int32_t (*Bind
)(PP_Resource udp_socket
,
279 struct PP_CompletionCallback callback
);
280 PP_Resource (*GetBoundAddress
)(PP_Resource udp_socket
);
281 int32_t (*RecvFrom
)(PP_Resource udp_socket
,
285 struct PP_CompletionCallback callback
);
286 int32_t (*SendTo
)(PP_Resource udp_socket
,
290 struct PP_CompletionCallback callback
);
291 void (*Close
)(PP_Resource udp_socket
);
292 int32_t (*SetOption
)(PP_Resource udp_socket
,
293 PP_UDPSocket_Option name
,
295 struct PP_CompletionCallback callback
);
298 struct PPB_UDPSocket_1_1
{
299 PP_Resource (*Create
)(PP_Instance instance
);
300 PP_Bool (*IsUDPSocket
)(PP_Resource resource
);
301 int32_t (*Bind
)(PP_Resource udp_socket
,
303 struct PP_CompletionCallback callback
);
304 PP_Resource (*GetBoundAddress
)(PP_Resource udp_socket
);
305 int32_t (*RecvFrom
)(PP_Resource udp_socket
,
309 struct PP_CompletionCallback callback
);
310 int32_t (*SendTo
)(PP_Resource udp_socket
,
314 struct PP_CompletionCallback callback
);
315 void (*Close
)(PP_Resource udp_socket
);
316 int32_t (*SetOption
)(PP_Resource udp_socket
,
317 PP_UDPSocket_Option name
,
319 struct PP_CompletionCallback callback
);
325 #endif /* PPAPI_C_PPB_UDP_SOCKET_H_ */