Pepper_42_C_interfaces
ppb_udp_socket.h
Go to the documentation of this file.
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.
4  */
5 
6 /* From ppb_udp_socket.idl modified Thu Jan 8 16:30:38 2015. */
7 
8 #ifndef PPAPI_C_PPB_UDP_SOCKET_H_
9 #define PPAPI_C_PPB_UDP_SOCKET_H_
10 
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"
18 
19 #define PPB_UDPSOCKET_INTERFACE_1_0 "PPB_UDPSocket;1.0"
20 #define PPB_UDPSOCKET_INTERFACE PPB_UDPSOCKET_INTERFACE_1_0
21 
22 /**
23  * @file
24  * This file defines the <code>PPB_UDPSocket</code> interface.
25  */
26 
27 
28 /**
29  * @addtogroup Enums
30  * @{
31  */
32 /**
33  * Option names used by <code>SetOption()</code>.
34  */
35 typedef enum {
36  /**
37  * Allows the socket to share the local address to which it will be bound with
38  * other processes. Value's type should be <code>PP_VARTYPE_BOOL</code>.
39  * This option can only be set before calling <code>Bind()</code>.
40  */
42  /**
43  * Allows sending and receiving packets to and from broadcast addresses.
44  * Value's type should be <code>PP_VARTYPE_BOOL</code>.
45  * This option can only be set before calling <code>Bind()</code>.
46  */
48  /**
49  * Specifies the total per-socket buffer space reserved for sends. Value's
50  * type should be <code>PP_VARTYPE_INT32</code>.
51  * This option can only be set after a successful <code>Bind()</code> call.
52  *
53  * Note: This is only treated as a hint for the browser to set the buffer
54  * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
55  * guarantee it will conform to the size.
56  */
58  /**
59  * Specifies the total per-socket buffer space reserved for receives. Value's
60  * type should be <code>PP_VARTYPE_INT32</code>.
61  * This option can only be set after a successful <code>Bind()</code> call.
62  *
63  * Note: This is only treated as a hint for the browser to set the buffer
64  * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
65  * guarantee it will conform to the size.
66  */
68  /**
69  * Set or read a boolean argument that determines whether sent multicast
70  * packets should be looped back to the local sockets. Value's type should be
71  * <code>PP_VARTYPE_BOOL</code>.
72  *
73  * Set/Get value using <code>PP_SocketOptionValue</code>.
74  * 0 - loopback inactive, 1 - loopback active
75  */
77  /**
78  * 'Time To Live' for multicast packets. If not otherwise specified, multicast
79  * datagrams are sent with a default value of 1, to prevent them to be
80  * forwarded beyond the local network. Value should be
81  * <code>PP_VARTYPE_INT32</code> type, from 0 to 255.
82  *
83  * Set/Get value using <code>PP_SocketOptionValue</code>. Range: 0-255
84  */
88 /**
89  * @}
90  */
91 
92 /**
93  * @addtogroup Interfaces
94  * @{
95  */
96 /**
97  * The <code>PPB_UDPSocket</code> interface provides UDP socket operations.
98  *
99  * Permissions: Apps permission <code>socket</code> with subrule
100  * <code>udp-bind</code> is required for <code>Bind()</code>; subrule
101  * <code>udp-send-to</code> is required for <code>SendTo()</code>.
102  * For more details about network communication permissions, please see:
103  * http://developer.chrome.com/apps/app_network.html
104  */
106  /**
107  * Creates a UDP socket resource.
108  *
109  * @param[in] instance A <code>PP_Instance</code> identifying one instance of
110  * a module.
111  *
112  * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0
113  * on failure.
114  */
116  /**
117  * Determines if a given resource is a UDP socket.
118  *
119  * @param[in] resource A <code>PP_Resource</code> to check.
120  *
121  * @return <code>PP_TRUE</code> if the input is a <code>PPB_UDPSocket</code>
122  * resource; <code>PP_FALSE</code> otherwise.
123  */
125  /**
126  * Binds the socket to the given address.
127  *
128  * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
129  * socket.
130  * @param[in] addr A <code>PPB_NetAddress</code> resource.
131  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
132  * completion.
133  *
134  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
135  * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
136  * required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be returned
137  * if the address is already in use.
138  */
139  int32_t (*Bind)(PP_Resource udp_socket,
140  PP_Resource addr,
141  struct PP_CompletionCallback callback);
142  /**
143  * Gets the address that the socket is bound to. The socket must be bound.
144  *
145  * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
146  * socket.
147  *
148  * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
149  */
151  /**
152  * Receives data from the socket and stores the source address. The socket
153  * must be bound.
154  *
155  * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
156  * socket.
157  * @param[out] buffer The buffer to store the received data on success. It
158  * must be at least as large as <code>num_bytes</code>.
159  * @param[in] num_bytes The number of bytes to receive.
160  * @param[out] addr A <code>PPB_NetAddress</code> resource to store the source
161  * address on success.
162  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
163  * completion.
164  *
165  * @return A non-negative number on success to indicate how many bytes have
166  * been received; otherwise, an error code from <code>pp_errors.h</code>.
167  */
168  int32_t (*RecvFrom)(PP_Resource udp_socket,
169  char* buffer,
170  int32_t num_bytes,
171  PP_Resource* addr,
172  struct PP_CompletionCallback callback);
173  /**
174  * Sends data to a specific destination. The socket must be bound.
175  *
176  * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
177  * socket.
178  * @param[in] buffer The buffer containing the data to send.
179  * @param[in] num_bytes The number of bytes to send.
180  * @param[in] addr A <code>PPB_NetAddress</code> resource holding the
181  * destination address.
182  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
183  * completion.
184  *
185  * @return A non-negative number on success to indicate how many bytes have
186  * been sent; otherwise, an error code from <code>pp_errors.h</code>.
187  * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
188  * required permissions.
189  */
190  int32_t (*SendTo)(PP_Resource udp_socket,
191  const char* buffer,
192  int32_t num_bytes,
193  PP_Resource addr,
194  struct PP_CompletionCallback callback);
195  /**
196  * Cancels all pending reads and writes, and closes the socket. Any pending
197  * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if
198  * pending IO was interrupted. After a call to this method, no output
199  * parameters passed into previous <code>RecvFrom()</code> calls will be
200  * accessed. It is not valid to call <code>Bind()</code> again.
201  *
202  * The socket is implicitly closed if it is destroyed, so you are not
203  * required to call this method.
204  *
205  * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
206  * socket.
207  */
208  void (*Close)(PP_Resource udp_socket);
209  /**
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.
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>.
222  */
223  int32_t (*SetOption)(PP_Resource udp_socket,
224  PP_UDPSocket_Option name,
225  struct PP_Var value,
226  struct PP_CompletionCallback callback);
227 };
228 
230 /**
231  * @}
232  */
233 
234 #endif /* PPAPI_C_PPB_UDP_SOCKET_H_ */
235 
void(* Close)(PP_Resource udp_socket)
int32_t(* RecvFrom)(PP_Resource udp_socket, char *buffer, int32_t num_bytes, PP_Resource *addr, struct PP_CompletionCallback callback)
int32_t(* SendTo)(PP_Resource udp_socket, const char *buffer, int32_t num_bytes, PP_Resource addr, struct PP_CompletionCallback callback)
PP_UDPSocket_Option
int32_t PP_Resource
Definition: pp_resource.h:40
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_UDPSocket_Option, 4)
union PP_VarValue value
Definition: pp_var.h:180
Definition: pp_var.h:166
PP_Resource(* GetBoundAddress)(PP_Resource udp_socket)
PP_Bool(* IsUDPSocket)(PP_Resource resource)
int32_t PP_Instance
Definition: pp_instance.h:34
int32_t(* SetOption)(PP_Resource udp_socket, PP_UDPSocket_Option name, struct PP_Var value, struct PP_CompletionCallback callback)
PP_Bool
Definition: pp_bool.h:30
int32_t(* Bind)(PP_Resource udp_socket, PP_Resource addr, struct PP_CompletionCallback callback)
PP_Resource(* Create)(PP_Instance instance)