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 Wed Jan 14 13:13:19 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 PPB_UDPSOCKET_INTERFACE_1_1
25 * This file defines the <code>PPB_UDPSocket</code> interface.
34 * Option names used by <code>SetOption()</code>.
38 * Allows the socket to share the local address to which it will be bound with
39 * other processes. Value's type should be <code>PP_VARTYPE_BOOL</code>.
40 * This option can only be set before calling <code>Bind()</code>.
42 PP_UDPSOCKET_OPTION_ADDRESS_REUSE
= 0,
44 * Allows sending and receiving packets to and from broadcast addresses.
45 * Value's type should be <code>PP_VARTYPE_BOOL</code>.
46 * On version 1.0, this option can only be set before calling
47 * <code>Bind()</code>. On version 1.1 or later, there is no such limitation.
49 PP_UDPSOCKET_OPTION_BROADCAST
= 1,
51 * Specifies the total per-socket buffer space reserved for sends. Value's
52 * type should be <code>PP_VARTYPE_INT32</code>.
53 * On version 1.0, this option can only be set after a successful
54 * <code>Bind()</code> call. On version 1.1 or later, there is no such
57 * Note: This is only treated as a hint for the browser to set the buffer
58 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
59 * guarantee it will conform to the size.
61 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE
= 2,
63 * Specifies the total per-socket buffer space reserved for receives. Value's
64 * type should be <code>PP_VARTYPE_INT32</code>.
65 * On version 1.0, this option can only be set after a successful
66 * <code>Bind()</code> call. On version 1.1 or later, there is no such
69 * Note: This is only treated as a hint for the browser to set the buffer
70 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
71 * guarantee it will conform to the size.
73 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE
= 3
74 } PP_UDPSocket_Option
;
75 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_UDPSocket_Option
, 4);
81 * @addtogroup Interfaces
85 * The <code>PPB_UDPSocket</code> interface provides UDP socket operations.
87 * Permissions: Apps permission <code>socket</code> with subrule
88 * <code>udp-bind</code> is required for <code>Bind()</code>; subrule
89 * <code>udp-send-to</code> is required for <code>SendTo()</code>.
90 * For more details about network communication permissions, please see:
91 * http://developer.chrome.com/apps/app_network.html
93 struct PPB_UDPSocket_1_1
{
95 * Creates a UDP socket resource.
97 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
100 * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0
103 PP_Resource (*Create
)(PP_Instance instance
);
105 * Determines if a given resource is a UDP socket.
107 * @param[in] resource A <code>PP_Resource</code> to check.
109 * @return <code>PP_TRUE</code> if the input is a <code>PPB_UDPSocket</code>
110 * resource; <code>PP_FALSE</code> otherwise.
112 PP_Bool (*IsUDPSocket
)(PP_Resource resource
);
114 * Binds the socket to the given address.
116 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
118 * @param[in] addr A <code>PPB_NetAddress</code> resource.
119 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
122 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
123 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
124 * required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be returned
125 * if the address is already in use.
127 int32_t (*Bind
)(PP_Resource udp_socket
,
129 struct PP_CompletionCallback callback
);
131 * Gets the address that the socket is bound to. The socket must be bound.
133 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
136 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
138 PP_Resource (*GetBoundAddress
)(PP_Resource udp_socket
);
140 * Receives data from the socket and stores the source address. The socket
143 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
145 * @param[out] buffer The buffer to store the received data on success. It
146 * must be at least as large as <code>num_bytes</code>.
147 * @param[in] num_bytes The number of bytes to receive.
148 * @param[out] addr A <code>PPB_NetAddress</code> resource to store the source
149 * address on success.
150 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
153 * @return A non-negative number on success to indicate how many bytes have
154 * been received; otherwise, an error code from <code>pp_errors.h</code>.
156 int32_t (*RecvFrom
)(PP_Resource udp_socket
,
160 struct PP_CompletionCallback callback
);
162 * Sends data to a specific destination. The socket must be bound.
164 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
166 * @param[in] buffer The buffer containing the data to send.
167 * @param[in] num_bytes The number of bytes to send.
168 * @param[in] addr A <code>PPB_NetAddress</code> resource holding the
169 * destination address.
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 sent; otherwise, an error code from <code>pp_errors.h</code>.
175 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
176 * required permissions.
177 * <code>PP_ERROR_INPROGRESS</code> will be returned if the socket is busy
178 * sending. The caller should wait until a pending send completes before
181 int32_t (*SendTo
)(PP_Resource udp_socket
,
185 struct PP_CompletionCallback callback
);
187 * Cancels all pending reads and writes, and closes the socket. Any pending
188 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if
189 * pending IO was interrupted. After a call to this method, no output
190 * parameters passed into previous <code>RecvFrom()</code> calls will be
191 * accessed. It is not valid to call <code>Bind()</code> again.
193 * The socket is implicitly closed if it is destroyed, so you are not
194 * required to call this method.
196 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
199 void (*Close
)(PP_Resource udp_socket
);
201 * Sets a socket option on the UDP socket.
202 * Please see the <code>PP_UDPSocket_Option</code> description for option
203 * names, value types and allowed values.
205 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
207 * @param[in] name The option to set.
208 * @param[in] value The option value to set.
209 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
212 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
214 int32_t (*SetOption
)(PP_Resource udp_socket
,
215 PP_UDPSocket_Option name
,
217 struct PP_CompletionCallback callback
);
220 typedef struct PPB_UDPSocket_1_1 PPB_UDPSocket
;
222 struct PPB_UDPSocket_1_0
{
223 PP_Resource (*Create
)(PP_Instance instance
);
224 PP_Bool (*IsUDPSocket
)(PP_Resource resource
);
225 int32_t (*Bind
)(PP_Resource udp_socket
,
227 struct PP_CompletionCallback callback
);
228 PP_Resource (*GetBoundAddress
)(PP_Resource udp_socket
);
229 int32_t (*RecvFrom
)(PP_Resource udp_socket
,
233 struct PP_CompletionCallback callback
);
234 int32_t (*SendTo
)(PP_Resource udp_socket
,
238 struct PP_CompletionCallback callback
);
239 void (*Close
)(PP_Resource udp_socket
);
240 int32_t (*SetOption
)(PP_Resource udp_socket
,
241 PP_UDPSocket_Option name
,
243 struct PP_CompletionCallback callback
);
249 #endif /* PPAPI_C_PPB_UDP_SOCKET_H_ */