OLD | NEW |
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 Thu Sep 19 14:01:43 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 Loading... |
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 * Binding the socket beforehand is optional. |
| 129 * |
| 130 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 131 * socket. |
105 * @param[in] addr A <code>PPB_NetAddress</code> resource. | 132 * @param[in] addr A <code>PPB_NetAddress</code> resource. |
106 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 133 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
107 * completion. | 134 * completion. |
108 * | 135 * |
109 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | 136 * @return An int32_t containing an error code from <code>pp_errors.h</code>, |
110 * including (but not limited to): | 137 * including (but not limited to): |
111 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required | 138 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required |
112 * permissions. | 139 * permissions. |
113 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is | 140 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is |
114 * unreachable. | 141 * unreachable. |
115 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was | 142 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was |
116 * refused. | 143 * refused. |
117 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. | 144 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. |
118 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed | 145 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed |
119 * out. | 146 * out. |
| 147 * |
| 148 * If the socket is listening/connected or has a pending listen/connect |
| 149 * request, <code>Connect()</code> will fail without starting a connection |
| 150 * attempt. Otherwise, any failure during the connection attempt will cause |
| 151 * the socket to be closed. |
120 */ | 152 */ |
121 int32_t (*Connect)(PP_Resource tcp_socket, | 153 int32_t (*Connect)(PP_Resource tcp_socket, |
122 PP_Resource addr, | 154 PP_Resource addr, |
123 struct PP_CompletionCallback callback); | 155 struct PP_CompletionCallback callback); |
124 /** | 156 /** |
125 * Gets the local address of the socket, if it is connected. | 157 * Gets the local address of the socket, if it is bound. |
126 * | 158 * |
127 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 159 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
128 * socket. | 160 * socket. |
129 * | 161 * |
130 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. | 162 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. |
131 */ | 163 */ |
132 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); | 164 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); |
133 /** | 165 /** |
134 * Gets the remote address of the socket, if it is connected. | 166 * Gets the remote address of the socket, if it is connected. |
135 * | 167 * |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 * completion. | 203 * completion. |
172 * | 204 * |
173 * @return A non-negative number on success to indicate how many bytes have | 205 * @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>. | 206 * been written; otherwise, an error code from <code>pp_errors.h</code>. |
175 */ | 207 */ |
176 int32_t (*Write)(PP_Resource tcp_socket, | 208 int32_t (*Write)(PP_Resource tcp_socket, |
177 const char* buffer, | 209 const char* buffer, |
178 int32_t bytes_to_write, | 210 int32_t bytes_to_write, |
179 struct PP_CompletionCallback callback); | 211 struct PP_CompletionCallback callback); |
180 /** | 212 /** |
181 * Cancels all pending reads and writes and disconnects the socket. Any | 213 * Starts listening. The socket must be bound and not connected. |
182 * pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> | 214 * |
183 * if pending IO was interrupted. After a call to this method, no output | 215 * @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 | 216 * socket. |
185 * accessed. It is not valid to call <code>Connect()</code> again. | 217 * @param[in] backlog A hint to determine the maximum length to which the |
| 218 * queue of pending connections may grow. |
| 219 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 220 * completion. |
| 221 * |
| 222 * @return An int32_t containing an error code from <code>pp_errors.h</code>, |
| 223 * including (but not limited to): |
| 224 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required |
| 225 * permissions. |
| 226 * - <code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening |
| 227 * on the same port. |
| 228 */ |
| 229 int32_t (*Listen)(PP_Resource tcp_socket, |
| 230 int32_t backlog, |
| 231 struct PP_CompletionCallback callback); |
| 232 /** |
| 233 * Accepts a connection. The socket must be listening. |
| 234 * |
| 235 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 236 * socket. |
| 237 * @param[out] accepted_tcp_socket Stores the accepted TCP socket on success. |
| 238 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 239 * completion. |
| 240 * |
| 241 * @return An int32_t containing an error code from <code>pp_errors.h</code>, |
| 242 * including (but not limited to): |
| 243 * - <code>PP_ERROR_CONNECTION_ABORTED</code>: A connection has been aborted. |
| 244 */ |
| 245 int32_t (*Accept)(PP_Resource tcp_socket, |
| 246 PP_Resource* accepted_tcp_socket, |
| 247 struct PP_CompletionCallback callback); |
| 248 /** |
| 249 * Cancels all pending operations and closes the socket. Any pending callbacks |
| 250 * will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was |
| 251 * interrupted. After a call to this method, no output buffer pointers passed |
| 252 * into previous <code>Read()</code> or <code>Accept()</code> calls will be |
| 253 * accessed. It is not valid to call <code>Connect()</code> or |
| 254 * <code>Listen()</code> again. |
186 * | 255 * |
187 * The socket is implicitly closed if it is destroyed, so you are not required | 256 * The socket is implicitly closed if it is destroyed, so you are not required |
188 * to call this method. | 257 * to call this method. |
189 * | 258 * |
190 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 259 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
191 * socket. | 260 * socket. |
192 */ | 261 */ |
193 void (*Close)(PP_Resource tcp_socket); | 262 void (*Close)(PP_Resource tcp_socket); |
194 /** | 263 /** |
195 * Sets a socket option on the TCP socket. | 264 * Sets a socket option on the TCP socket. |
196 * Please see the <code>PP_TCPSocket_Option</code> description for option | 265 * Please see the <code>PP_TCPSocket_Option</code> description for option |
197 * names, value types and allowed values. | 266 * names, value types and allowed values. |
198 * | 267 * |
199 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 268 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
200 * socket. | 269 * socket. |
201 * @param[in] name The option to set. | 270 * @param[in] name The option to set. |
202 * @param[in] value The option value to set. | 271 * @param[in] value The option value to set. |
203 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 272 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
204 * completion. | 273 * completion. |
205 * | 274 * |
206 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 275 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
207 */ | 276 */ |
208 int32_t (*SetOption)(PP_Resource tcp_socket, | 277 int32_t (*SetOption)(PP_Resource tcp_socket, |
209 PP_TCPSocket_Option name, | 278 PP_TCPSocket_Option name, |
210 struct PP_Var value, | 279 struct PP_Var value, |
211 struct PP_CompletionCallback callback); | 280 struct PP_CompletionCallback callback); |
212 }; | 281 }; |
213 | 282 |
214 typedef struct PPB_TCPSocket_1_0 PPB_TCPSocket; | 283 typedef struct PPB_TCPSocket_1_1 PPB_TCPSocket; |
| 284 |
| 285 struct PPB_TCPSocket_1_0 { |
| 286 PP_Resource (*Create)(PP_Instance instance); |
| 287 PP_Bool (*IsTCPSocket)(PP_Resource resource); |
| 288 int32_t (*Connect)(PP_Resource tcp_socket, |
| 289 PP_Resource addr, |
| 290 struct PP_CompletionCallback callback); |
| 291 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); |
| 292 PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket); |
| 293 int32_t (*Read)(PP_Resource tcp_socket, |
| 294 char* buffer, |
| 295 int32_t bytes_to_read, |
| 296 struct PP_CompletionCallback callback); |
| 297 int32_t (*Write)(PP_Resource tcp_socket, |
| 298 const char* buffer, |
| 299 int32_t bytes_to_write, |
| 300 struct PP_CompletionCallback callback); |
| 301 void (*Close)(PP_Resource tcp_socket); |
| 302 int32_t (*SetOption)(PP_Resource tcp_socket, |
| 303 PP_TCPSocket_Option name, |
| 304 struct PP_Var value, |
| 305 struct PP_CompletionCallback callback); |
| 306 }; |
215 /** | 307 /** |
216 * @} | 308 * @} |
217 */ | 309 */ |
218 | 310 |
219 #endif /* PPAPI_C_PPB_TCP_SOCKET_H_ */ | 311 #endif /* PPAPI_C_PPB_TCP_SOCKET_H_ */ |
220 | 312 |
OLD | NEW |