Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: ppapi/c/dev/ppb_udp_socket_dev.h

Issue 16938011: Update comments of the Pepper networking APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* Copyright 2013 The Chromium Authors. All rights reserved. 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 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /* From dev/ppb_udp_socket_dev.idl modified Thu Jun 13 09:38:45 2013. */ 6 /* From dev/ppb_udp_socket_dev.idl modified Thu Jun 20 13:17:52 2013. */
7 7
8 #ifndef PPAPI_C_DEV_PPB_UDP_SOCKET_DEV_H_ 8 #ifndef PPAPI_C_DEV_PPB_UDP_SOCKET_DEV_H_
9 #define PPAPI_C_DEV_PPB_UDP_SOCKET_DEV_H_ 9 #define PPAPI_C_DEV_PPB_UDP_SOCKET_DEV_H_
10 10
11 #include "ppapi/c/pp_bool.h" 11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h" 12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_instance.h" 13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_macros.h" 14 #include "ppapi/c/pp_macros.h"
15 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/pp_stdint.h" 16 #include "ppapi/c/pp_stdint.h"
17 #include "ppapi/c/pp_var.h" 17 #include "ppapi/c/pp_var.h"
18 18
19 #define PPB_UDPSOCKET_DEV_INTERFACE_0_1 "PPB_UDPSocket(Dev);0.1" 19 #define PPB_UDPSOCKET_DEV_INTERFACE_0_1 "PPB_UDPSocket(Dev);0.1"
20 #define PPB_UDPSOCKET_DEV_INTERFACE PPB_UDPSOCKET_DEV_INTERFACE_0_1 20 #define PPB_UDPSOCKET_DEV_INTERFACE PPB_UDPSOCKET_DEV_INTERFACE_0_1
21 21
22 /** 22 /**
23 * @file 23 * @file
24 * This file defines the <code>PPB_UDPSocket_Dev</code> interface. 24 * This file defines the <code>PPB_UDPSocket_Dev</code> interface.
25 * TODO(yzshen): Tidy up the document.
26 */ 25 */
27 26
28 27
29 /** 28 /**
30 * @addtogroup Enums 29 * @addtogroup Enums
31 * @{ 30 * @{
32 */ 31 */
32 /**
33 * Option names used by <code>SetOption()</code>.
34 */
33 typedef enum { 35 typedef enum {
34 /* Allows the socket to share the local address to which it will be bound with 36 /**
35 * other processes. Value's type should be PP_VARTYPE_BOOL. */ 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 */
36 PP_UDPSOCKET_OPTION_ADDRESS_REUSE = 0, 41 PP_UDPSOCKET_OPTION_ADDRESS_REUSE = 0,
37 /* Allows sending and receiving packets to and from broadcast addresses. 42 /**
38 * Value's type should be PP_VARTYPE_BOOL. */ 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 */
39 PP_UDPSOCKET_OPTION_BROADCAST = 1, 47 PP_UDPSOCKET_OPTION_BROADCAST = 1,
40 /* Specifies the total per-socket buffer space reserved for sends. Value's 48 /**
41 * type should be PP_VARTYPE_INT32. 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 *
42 * Note: This is only treated as a hint for the browser to set the buffer 53 * Note: This is only treated as a hint for the browser to set the buffer
43 * size. Even if SetOption() reports that this option has been successfully 54 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
44 * set, the browser doesn't guarantee it will conform to it. */ 55 * guarantee it will conform to the size.
56 */
45 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE = 2, 57 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE = 2,
46 /* Specifies the total per-socket buffer space reserved for receives. Value's 58 /**
47 * type should be PP_VARTYPE_INT32. 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 *
48 * Note: This is only treated as a hint for the browser to set the buffer 63 * Note: This is only treated as a hint for the browser to set the buffer
49 * size. Even if SetOption() reports that this option has been successfully 64 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
50 * set, the browser doesn't guarantee it will conform to it. */ 65 * guarantee it will conform to the size.
66 */
51 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE = 3 67 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE = 3
52 } PP_UDPSocket_Option_Dev; 68 } PP_UDPSocket_Option_Dev;
53 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_UDPSocket_Option_Dev, 4); 69 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_UDPSocket_Option_Dev, 4);
54 /** 70 /**
55 * @} 71 * @}
56 */ 72 */
57 73
58 /** 74 /**
59 * @addtogroup Interfaces 75 * @addtogroup Interfaces
60 * @{ 76 * @{
61 */ 77 */
78 /**
79 * The <code>PPB_UDPSocket_Dev</code> interface provides UDP socket operations.
80 *
81 * Permissions: Apps permission <code>socket</code> with subrule
82 * <code>udp-bind</code> is required for <code>Bind()</code>; subrule
83 * <code>udp-send-to</code> is required for <code>SendTo()</code>.
84 * For more details about network communication permissions, please see:
85 * http://developer.chrome.com/apps/app_network.html
86 */
62 struct PPB_UDPSocket_Dev_0_1 { 87 struct PPB_UDPSocket_Dev_0_1 {
63 /** 88 /**
64 * Creates a UDP socket resource. 89 * Creates a UDP socket resource.
90 *
91 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
92 * a module.
93 *
94 * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0
95 * on failure.
65 */ 96 */
66 PP_Resource (*Create)(PP_Instance instance); 97 PP_Resource (*Create)(PP_Instance instance);
67 /** 98 /**
68 * Determines if a given resource is a UDP socket. 99 * Determines if a given resource is a UDP socket.
100 *
101 * @param[in] resource A <code>PP_Resource</code> to check.
102 *
103 * @return <code>PP_TRUE</code> if the input is a
104 * <code>PPB_UDPSocket_Dev</code> resource; <code>PP_FALSE</code>
105 * otherwise.
69 */ 106 */
70 PP_Bool (*IsUDPSocket)(PP_Resource resource); 107 PP_Bool (*IsUDPSocket)(PP_Resource resource);
71 /** 108 /**
72 * Binds to the address given by |addr|, which is a PPB_NetAddress_Dev 109 * Binds the socket to the given address.
73 * resource. 110 *
111 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
112 * socket.
113 * @param[in] addr A <code>PPB_NetAddress_Dev</code> resource.
114 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
115 * completion.
116 *
117 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
118 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
119 * required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be returned
120 * if the address is already in use.
74 */ 121 */
75 int32_t (*Bind)(PP_Resource udp_socket, 122 int32_t (*Bind)(PP_Resource udp_socket,
76 PP_Resource addr, 123 PP_Resource addr,
77 struct PP_CompletionCallback callback); 124 struct PP_CompletionCallback callback);
78 /** 125 /**
79 * Returns the address that the socket has bound to, as a PPB_NetAddress_Dev 126 * Gets the address that the socket has bound to. The socket must be bound.
80 * resource. Bind must be called and succeed first. Returns 0 if Bind fails, 127 *
81 * or if Close has been called. 128 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
129 * socket.
130 *
131 * @return A <code>PPB_NetAddress_Dev</code> resource on success or 0 on
132 * failure.
82 */ 133 */
83 PP_Resource (*GetBoundAddress)(PP_Resource udp_socket); 134 PP_Resource (*GetBoundAddress)(PP_Resource udp_socket);
84 /** 135 /**
85 * Performs a non-blocking recvfrom call on socket. 136 * Receives data from the socket and stores the source address. The socket
86 * Bind must be called first. |callback| is invoked when recvfrom reads data. 137 * must be bound.
87 * |addr| will store a PPB_NetAddress_Dev resource on success. 138 *
139 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
140 * socket.
141 * @param[out] buffer The buffer to store the received data on success. It
142 * must be at least as large as <code>num_bytes</code>.
143 * @param[in] num_bytes The number of bytes to receive.
144 * @param[out] addr A <code>PPB_NetAddress_Dev</code> resource to store the
145 * source address on success.
146 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
147 * completion.
148 *
149 * @return A non-negative number on success to indicate how many bytes have
150 * been received; otherwise, an error code from <code>pp_errors.h</code>.
88 */ 151 */
89 int32_t (*RecvFrom)(PP_Resource udp_socket, 152 int32_t (*RecvFrom)(PP_Resource udp_socket,
90 char* buffer, 153 char* buffer,
91 int32_t num_bytes, 154 int32_t num_bytes,
92 PP_Resource* addr, 155 PP_Resource* addr,
93 struct PP_CompletionCallback callback); 156 struct PP_CompletionCallback callback);
94 /** 157 /**
95 * Performs a non-blocking sendto call on the socket. 158 * Sends data to a specific destination. The socket must be bound.
96 * Bind must be called first. |addr| is a PPB_NetAddress_Dev resource holding 159 *
97 * the target address. |callback| is invoked when sendto completes. 160 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
161 * socket.
162 * @param[in] buffer The buffer containing the data to send.
163 * @param[in] num_bytes The number of bytes to send.
164 * @param[in] addr A <code>PPB_NetAddress_Dev</code> resource holding the
165 * destination address.
166 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
167 * completion.
168 *
169 * @return A non-negative number on success to indicate how many bytes have
170 * been sent; otherwise, an error code from <code>pp_errors.h</code>.
171 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
172 * required permissions.
98 */ 173 */
99 int32_t (*SendTo)(PP_Resource udp_socket, 174 int32_t (*SendTo)(PP_Resource udp_socket,
100 const char* buffer, 175 const char* buffer,
101 int32_t num_bytes, 176 int32_t num_bytes,
102 PP_Resource addr, 177 PP_Resource addr,
103 struct PP_CompletionCallback callback); 178 struct PP_CompletionCallback callback);
104 /** 179 /**
105 * Cancels all pending reads and writes, and closes the socket. 180 * Cancels all pending reads and writes, and closes the socket. Any pending
181 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if
182 * pending IO was interrupted. After a call to this method, not output
183 * parameters passed into previous <code>RecvFrom()</code> calls will be
184 * accessed. It is not valid to call <code>Bind()</code> again.
185 *
186 * The socket is implicitly closed if it is destroyed, so you are not
187 * required to call this method.
188 *
189 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
190 * socket.
106 */ 191 */
107 void (*Close)(PP_Resource udp_socket); 192 void (*Close)(PP_Resource udp_socket);
108 /** 193 /**
109 * Sets a socket option to |udp_socket|. Should be called before Bind(). 194 * Sets a socket option on the UDP socket.
110 * See the PP_UDPSocket_Option_Dev description for option names, value types 195 * Please see the <code>PP_UDPSocket_Option_Dev</code> description for option
111 * and allowed values. 196 * names, value types and allowed values.
112 * Returns PP_OK on success. Otherwise, returns PP_ERROR_BADRESOURCE (if bad 197 *
113 * |udp_socket| provided), PP_ERROR_BADARGUMENT (if bad name/value/value's 198 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
114 * type provided) or PP_ERROR_FAILED in the case of internal errors. 199 * socket.
200 * @param[in] name The option type to set.
201 * @param[in] value The option value to set.
202 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
203 * completion.
204 *
205 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
115 */ 206 */
116 int32_t (*SetOption)(PP_Resource udp_socket, 207 int32_t (*SetOption)(PP_Resource udp_socket,
117 PP_UDPSocket_Option_Dev name, 208 PP_UDPSocket_Option_Dev name,
118 struct PP_Var value, 209 struct PP_Var value,
119 struct PP_CompletionCallback callback); 210 struct PP_CompletionCallback callback);
120 }; 211 };
121 212
122 typedef struct PPB_UDPSocket_Dev_0_1 PPB_UDPSocket_Dev; 213 typedef struct PPB_UDPSocket_Dev_0_1 PPB_UDPSocket_Dev;
123 /** 214 /**
124 * @} 215 * @}
125 */ 216 */
126 217
127 #endif /* PPAPI_C_DEV_PPB_UDP_SOCKET_DEV_H_ */ 218 #endif /* PPAPI_C_DEV_PPB_UDP_SOCKET_DEV_H_ */
128 219
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698