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

Side by Side Diff: ppapi/c/ppb_tcp_socket.h

Issue 24195004: PPB_TCPSocket: add support for TCP server socket operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 ppb_tcp_socket.idl modified Sat Jun 22 11:17:34 2013. */ 6 /* From ppb_tcp_socket.idl modified Wed Sep 18 12:20:53 2013. */
7 7
8 #ifndef PPAPI_C_PPB_TCP_SOCKET_H_ 8 #ifndef PPAPI_C_PPB_TCP_SOCKET_H_
9 #define PPAPI_C_PPB_TCP_SOCKET_H_ 9 #define PPAPI_C_PPB_TCP_SOCKET_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_TCPSOCKET_INTERFACE_1_0 "PPB_TCPSocket;1.0" 19 #define PPB_TCPSOCKET_INTERFACE_1_0 "PPB_TCPSocket;1.0"
20 #define PPB_TCPSOCKET_INTERFACE PPB_TCPSOCKET_INTERFACE_1_0 20 #define PPB_TCPSOCKET_INTERFACE_1_1 "PPB_TCPSocket;1.1"
21 #define PPB_TCPSOCKET_INTERFACE PPB_TCPSOCKET_INTERFACE_1_1
21 22
22 /** 23 /**
23 * @file 24 * @file
24 * This file defines the <code>PPB_TCPSocket</code> interface. 25 * This file defines the <code>PPB_TCPSocket</code> interface.
25 */ 26 */
26 27
27 28
28 /** 29 /**
29 * @addtogroup Enums 30 * @addtogroup Enums
30 * @{ 31 * @{
(...skipping 20 matching lines...) Expand all
51 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, 52 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1,
52 /** 53 /**
53 * Specifies the total per-socket buffer space reserved for receives. Value's 54 * Specifies the total per-socket buffer space reserved for receives. Value's
54 * type should be <code>PP_VARTYPE_INT32</code>. 55 * type should be <code>PP_VARTYPE_INT32</code>.
55 * This option can only be set after a successful <code>Connect()</code> call. 56 * This option can only be set after a successful <code>Connect()</code> call.
56 * 57 *
57 * Note: This is only treated as a hint for the browser to set the buffer 58 * 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 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
59 * guarantee it will conform to the size. 60 * guarantee it will conform to the size.
60 */ 61 */
61 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 62 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2,
63 /**
64 * Allows the socket to share the local address to which it will be bound.
65 * Value's type should be <code>PP_VARTYPE_BOOL</code>.
66 * This option can only be set before calling <code>Bind()</code>.
67 * Supported since version 1.1.
68 */
69 PP_TCPSOCKET_OPTION_ADDRESS_REUSE = 3
62 } PP_TCPSocket_Option; 70 } PP_TCPSocket_Option;
63 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option, 4); 71 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option, 4);
64 /** 72 /**
65 * @} 73 * @}
66 */ 74 */
67 75
68 /** 76 /**
69 * @addtogroup Interfaces 77 * @addtogroup Interfaces
70 * @{ 78 * @{
71 */ 79 */
72 /** 80 /**
73 * The <code>PPB_TCPSocket</code> interface provides TCP socket operations. 81 * The <code>PPB_TCPSocket</code> interface provides TCP socket operations.
74 * 82 *
75 * Permissions: Apps permission <code>socket</code> with subrule 83 * Permissions: Apps permission <code>socket</code> with subrule
76 * <code>tcp-connect</code> is required for <code>Connect()</code>. 84 * <code>tcp-connect</code> is required for <code>Connect()</code>; subrule
85 * <code>tcp-listen</code> is required for <code>Listen()</code>.
77 * For more details about network communication permissions, please see: 86 * For more details about network communication permissions, please see:
78 * http://developer.chrome.com/apps/app_network.html 87 * http://developer.chrome.com/apps/app_network.html
79 */ 88 */
80 struct PPB_TCPSocket_1_0 { 89 struct PPB_TCPSocket_1_1 {
81 /** 90 /**
82 * Creates a TCP socket resource. 91 * Creates a TCP socket resource.
83 * 92 *
84 * @param[in] instance A <code>PP_Instance</code> identifying one instance of 93 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
85 * a module. 94 * a module.
86 * 95 *
87 * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0 96 * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0
88 * on failure. 97 * on failure.
89 */ 98 */
90 PP_Resource (*Create)(PP_Instance instance); 99 PP_Resource (*Create)(PP_Instance instance);
91 /** 100 /**
92 * Determines if a given resource is a TCP socket. 101 * Determines if a given resource is a TCP socket.
93 * 102 *
94 * @param[in] resource A <code>PP_Resource</code> to check. 103 * @param[in] resource A <code>PP_Resource</code> to check.
95 * 104 *
96 * @return <code>PP_TRUE</code> if the input is a 105 * @return <code>PP_TRUE</code> if the input is a
97 * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise. 106 * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise.
98 */ 107 */
99 PP_Bool (*IsTCPSocket)(PP_Resource resource); 108 PP_Bool (*IsTCPSocket)(PP_Resource resource);
100 /** 109 /**
101 * Connects the socket to the given address. 110 * Binds the socket to the given address. The socket must not be bound.
102 * 111 *
103 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 112 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
104 * socket. 113 * socket.
114 * @param[in] addr A <code>PPB_NetAddress</code> resource.
115 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
116 * completion.
117 *
118 * @return An int32_t containing an error code from <code>pp_errors.h</code>,
119 * including (but not limited to):
120 * - <code>PP_ERROR_ADDRESS_IN_USE</code>: the address is already in use.
121 * - <code>PP_ERROR_ADDRESS_INVALID</code>: the address is invalid.
122 */
123 int32_t (*Bind)(PP_Resource tcp_socket,
124 PP_Resource addr,
125 struct PP_CompletionCallback callback);
126 /**
127 * Connects the socket to the given address. The socket must not be listening.
128 *
129 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
130 * socket.
105 * @param[in] addr A <code>PPB_NetAddress</code> resource. 131 * @param[in] addr A <code>PPB_NetAddress</code> resource.
106 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 132 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
107 * completion. 133 * completion.
108 * 134 *
109 * @return An int32_t containing an error code from <code>pp_errors.h</code>, 135 * @return An int32_t containing an error code from <code>pp_errors.h</code>,
110 * including (but not limited to): 136 * including (but not limited to):
111 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required 137 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required
112 * permissions. 138 * permissions.
113 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is 139 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is
114 * unreachable. 140 * unreachable.
115 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was 141 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was
116 * refused. 142 * refused.
117 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. 143 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed.
118 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed 144 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed
119 * out. 145 * out.
146 *
147 * If the socket is listening/connected or has a pending listen/connect
148 * request, <code>Connect()</code> will fail without starting a connection
149 * attempt. Otherwise, any failure during the connection attempt will cause
150 * the socket to be closed.
120 */ 151 */
121 int32_t (*Connect)(PP_Resource tcp_socket, 152 int32_t (*Connect)(PP_Resource tcp_socket,
122 PP_Resource addr, 153 PP_Resource addr,
123 struct PP_CompletionCallback callback); 154 struct PP_CompletionCallback callback);
124 /** 155 /**
125 * Gets the local address of the socket, if it is connected. 156 * Gets the local address of the socket, if it is bound.
126 * 157 *
127 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 158 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
128 * socket. 159 * socket.
129 * 160 *
130 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. 161 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
131 */ 162 */
132 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); 163 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
133 /** 164 /**
134 * Gets the remote address of the socket, if it is connected. 165 * Gets the remote address of the socket, if it is connected.
135 * 166 *
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 * completion. 202 * completion.
172 * 203 *
173 * @return A non-negative number on success to indicate how many bytes have 204 * @return A non-negative number on success to indicate how many bytes have
174 * been written; otherwise, an error code from <code>pp_errors.h</code>. 205 * been written; otherwise, an error code from <code>pp_errors.h</code>.
175 */ 206 */
176 int32_t (*Write)(PP_Resource tcp_socket, 207 int32_t (*Write)(PP_Resource tcp_socket,
177 const char* buffer, 208 const char* buffer,
178 int32_t bytes_to_write, 209 int32_t bytes_to_write,
179 struct PP_CompletionCallback callback); 210 struct PP_CompletionCallback callback);
180 /** 211 /**
181 * Cancels all pending reads and writes and disconnects the socket. Any 212 * Starts listening. The socket must be bound and not connected.
182 * pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> 213 *
183 * if pending IO was interrupted. After a call to this method, no output 214 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
184 * buffer pointers passed into previous <code>Read()</code> calls will be 215 * socket.
185 * accessed. It is not valid to call <code>Connect()</code> again. 216 * @param[in] backlog A hint to determine the maximum length to which the
217 * queue of pending connections may grow.
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 * including (but not limited to):
223 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required
224 * permissions.
225 * - <code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening
226 * on the same port.
227 */
228 int32_t (*Listen)(PP_Resource tcp_socket,
229 int32_t backlog,
230 struct PP_CompletionCallback callback);
231 /**
232 * Accepts a connection. The socket must be listening.
233 *
234 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
235 * socket.
236 * @param[out] accepted_tcp_socket Stores the accepted TCP socket on success.
237 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
238 * completion.
239 *
240 * @return An int32_t containing an error code from <code>pp_errors.h</code>,
241 * including (but not limited to):
242 * - <code>PP_ERROR_CONNECTION_ABORTED</code>: A connection has been aborted.
243 */
244 int32_t (*Accept)(PP_Resource tcp_socket,
245 PP_Resource* accepted_tcp_socket,
246 struct PP_CompletionCallback callback);
247 /**
248 * Cancels all pending operations and closes the socket. Any pending callbacks
249 * will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was
250 * interrupted. After a call to this method, no output buffer pointers passed
251 * into previous <code>Read()</code> or <code>Accept()</code> calls will be
252 * accessed. It is not valid to call <code>Connect()</code> or
253 * <code>Listen()</code> again.
186 * 254 *
187 * The socket is implicitly closed if it is destroyed, so you are not required 255 * The socket is implicitly closed if it is destroyed, so you are not required
188 * to call this method. 256 * to call this method.
189 * 257 *
190 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 258 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
191 * socket. 259 * socket.
192 */ 260 */
193 void (*Close)(PP_Resource tcp_socket); 261 void (*Close)(PP_Resource tcp_socket);
194 /** 262 /**
195 * Sets a socket option on the TCP socket. 263 * Sets a socket option on the TCP socket.
196 * Please see the <code>PP_TCPSocket_Option</code> description for option 264 * Please see the <code>PP_TCPSocket_Option</code> description for option
197 * names, value types and allowed values. 265 * names, value types and allowed values.
198 * 266 *
199 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 267 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
200 * socket. 268 * socket.
201 * @param[in] name The option to set. 269 * @param[in] name The option to set.
202 * @param[in] value The option value to set. 270 * @param[in] value The option value to set.
203 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 271 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
204 * completion. 272 * completion.
205 * 273 *
206 * @return An int32_t containing an error code from <code>pp_errors.h</code>. 274 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
207 */ 275 */
208 int32_t (*SetOption)(PP_Resource tcp_socket, 276 int32_t (*SetOption)(PP_Resource tcp_socket,
209 PP_TCPSocket_Option name, 277 PP_TCPSocket_Option name,
210 struct PP_Var value, 278 struct PP_Var value,
211 struct PP_CompletionCallback callback); 279 struct PP_CompletionCallback callback);
212 }; 280 };
213 281
214 typedef struct PPB_TCPSocket_1_0 PPB_TCPSocket; 282 typedef struct PPB_TCPSocket_1_1 PPB_TCPSocket;
283
284 struct PPB_TCPSocket_1_0 {
285 PP_Resource (*Create)(PP_Instance instance);
286 PP_Bool (*IsTCPSocket)(PP_Resource resource);
287 int32_t (*Connect)(PP_Resource tcp_socket,
288 PP_Resource addr,
289 struct PP_CompletionCallback callback);
290 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
291 PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket);
292 int32_t (*Read)(PP_Resource tcp_socket,
293 char* buffer,
294 int32_t bytes_to_read,
295 struct PP_CompletionCallback callback);
296 int32_t (*Write)(PP_Resource tcp_socket,
297 const char* buffer,
298 int32_t bytes_to_write,
299 struct PP_CompletionCallback callback);
300 void (*Close)(PP_Resource tcp_socket);
301 int32_t (*SetOption)(PP_Resource tcp_socket,
302 PP_TCPSocket_Option name,
303 struct PP_Var value,
304 struct PP_CompletionCallback callback);
305 };
215 /** 306 /**
216 * @} 307 * @}
217 */ 308 */
218 309
219 #endif /* PPAPI_C_PPB_TCP_SOCKET_H_ */ 310 #endif /* PPAPI_C_PPB_TCP_SOCKET_H_ */
220 311
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698