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 /** | 6 /** |
7 * This file defines the <code>PPB_TCPSocket</code> interface. | 7 * This file defines the <code>PPB_TCPSocket</code> interface. |
8 */ | 8 */ |
9 | 9 |
10 [generate_thunk] | |
11 | |
12 label Chrome { | 10 label Chrome { |
13 M29 = 1.0 | 11 M29 = 1.0, |
12 M31 = 1.1 | |
14 }; | 13 }; |
15 | 14 |
16 /** | 15 /** |
17 * Option names used by <code>SetOption()</code>. | 16 * Option names used by <code>SetOption()</code>. |
18 */ | 17 */ |
19 [assert_size(4)] | 18 [assert_size(4)] |
20 enum PP_TCPSocket_Option { | 19 enum PP_TCPSocket_Option { |
21 /** | 20 /** |
22 * Disables coalescing of small writes to make TCP segments, and instead | 21 * Disables coalescing of small writes to make TCP segments, and instead |
23 * delivers data immediately. Value's type is <code>PP_VARTYPE_BOOL</code>. | 22 * delivers data immediately. Value's type is <code>PP_VARTYPE_BOOL</code>. |
(...skipping 14 matching lines...) Expand all Loading... | |
38 | 37 |
39 /** | 38 /** |
40 * Specifies the total per-socket buffer space reserved for receives. Value's | 39 * Specifies the total per-socket buffer space reserved for receives. Value's |
41 * type should be <code>PP_VARTYPE_INT32</code>. | 40 * type should be <code>PP_VARTYPE_INT32</code>. |
42 * This option can only be set after a successful <code>Connect()</code> call. | 41 * This option can only be set after a successful <code>Connect()</code> call. |
43 * | 42 * |
44 * Note: This is only treated as a hint for the browser to set the buffer | 43 * Note: This is only treated as a hint for the browser to set the buffer |
45 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't | 44 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't |
46 * guarantee it will conform to the size. | 45 * guarantee it will conform to the size. |
47 */ | 46 */ |
48 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 | 47 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2, |
48 | |
49 /** | |
50 * Allows the socket to share the local address to which it will be bound. | |
51 * Value's type should be <code>PP_VARTYPE_BOOL</code>. | |
52 * This option can only be set before calling <code>Bind()</code>. | |
53 * Supported since version 1.1. | |
54 */ | |
55 PP_TCPSOCKET_OPTION_ADDRESS_REUSE = 3 | |
49 }; | 56 }; |
50 | 57 |
51 /** | 58 /** |
52 * The <code>PPB_TCPSocket</code> interface provides TCP socket operations. | 59 * The <code>PPB_TCPSocket</code> interface provides TCP socket operations. |
53 * | 60 * |
54 * Permissions: Apps permission <code>socket</code> with subrule | 61 * Permissions: Apps permission <code>socket</code> with subrule |
55 * <code>tcp-connect</code> is required for <code>Connect()</code>. | 62 * <code>tcp-connect</code> is required for <code>Connect()</code>; subrule |
63 * <code>tcp-listen</code> is required for <code>Listen()</code>. | |
56 * For more details about network communication permissions, please see: | 64 * For more details about network communication permissions, please see: |
57 * http://developer.chrome.com/apps/app_network.html | 65 * http://developer.chrome.com/apps/app_network.html |
58 */ | 66 */ |
59 interface PPB_TCPSocket { | 67 interface PPB_TCPSocket { |
60 /** | 68 /** |
61 * Creates a TCP socket resource. | 69 * Creates a TCP socket resource. |
62 * | 70 * |
63 * @param[in] instance A <code>PP_Instance</code> identifying one instance of | 71 * @param[in] instance A <code>PP_Instance</code> identifying one instance of |
64 * a module. | 72 * a module. |
65 * | 73 * |
66 * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0 | 74 * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0 |
67 * on failure. | 75 * on failure. |
68 */ | 76 */ |
69 PP_Resource Create([in] PP_Instance instance); | 77 PP_Resource Create([in] PP_Instance instance); |
70 | 78 |
71 /** | 79 /** |
72 * Determines if a given resource is a TCP socket. | 80 * Determines if a given resource is a TCP socket. |
73 * | 81 * |
74 * @param[in] resource A <code>PP_Resource</code> to check. | 82 * @param[in] resource A <code>PP_Resource</code> to check. |
75 * | 83 * |
76 * @return <code>PP_TRUE</code> if the input is a | 84 * @return <code>PP_TRUE</code> if the input is a |
77 * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise. | 85 * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise. |
78 */ | 86 */ |
79 PP_Bool IsTCPSocket([in] PP_Resource resource); | 87 PP_Bool IsTCPSocket([in] PP_Resource resource); |
80 | 88 |
81 /** | 89 /** |
82 * Connects the socket to the given address. | 90 * Binds the socket to the given address. The socket must not be bound. |
83 * | 91 * |
84 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 92 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
85 * socket. | 93 * socket. |
94 * @param[in] addr A <code>PPB_NetAddress</code> resource. | |
95 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
96 * completion. | |
97 * | |
98 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | |
99 * including (but not limited to): | |
100 * - <code>PP_ERROR_ADDRESS_IN_USE</code>: the address is already in use. | |
101 * - <code>PP_ERROR_ADDRESS_INVALID</code>: the address is invalid. | |
102 */ | |
103 [version=1.1] | |
104 int32_t Bind([in] PP_Resource tcp_socket, | |
105 [in] PP_Resource addr, | |
106 [in] PP_CompletionCallback callback); | |
107 | |
108 /** | |
109 * Connects the socket to the given address. The socket must not be listening. | |
bbudge
2013/09/19 19:41:47
It's not clear to me when or if the socket must be
yzshen1
2013/09/19 21:12:15
Done.
| |
110 * | |
111 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
112 * socket. | |
86 * @param[in] addr A <code>PPB_NetAddress</code> resource. | 113 * @param[in] addr A <code>PPB_NetAddress</code> resource. |
87 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 114 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
88 * completion. | 115 * completion. |
89 * | 116 * |
90 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | 117 * @return An int32_t containing an error code from <code>pp_errors.h</code>, |
91 * including (but not limited to): | 118 * including (but not limited to): |
92 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required | 119 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required |
93 * permissions. | 120 * permissions. |
94 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is | 121 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is |
95 * unreachable. | 122 * unreachable. |
96 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was | 123 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was |
97 * refused. | 124 * refused. |
98 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. | 125 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. |
99 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed | 126 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed |
100 * out. | 127 * out. |
128 * | |
129 * If the socket is listening/connected or has a pending listen/connect | |
130 * request, <code>Connect()</code> will fail without starting a connection | |
131 * attempt. Otherwise, any failure during the connection attempt will cause | |
132 * the socket to be closed. | |
101 */ | 133 */ |
102 int32_t Connect([in] PP_Resource tcp_socket, | 134 int32_t Connect([in] PP_Resource tcp_socket, |
103 [in] PP_Resource addr, | 135 [in] PP_Resource addr, |
104 [in] PP_CompletionCallback callback); | 136 [in] PP_CompletionCallback callback); |
105 | 137 |
106 /** | 138 /** |
107 * Gets the local address of the socket, if it is connected. | 139 * Gets the local address of the socket, if it is bound. |
108 * | 140 * |
109 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 141 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
110 * socket. | 142 * socket. |
111 * | 143 * |
112 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. | 144 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. |
113 */ | 145 */ |
114 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); | 146 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); |
115 | 147 |
116 /** | 148 /** |
117 * Gets the remote address of the socket, if it is connected. | 149 * Gets the remote address of the socket, if it is connected. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 187 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
156 * completion. | 188 * completion. |
157 * | 189 * |
158 * @return A non-negative number on success to indicate how many bytes have | 190 * @return A non-negative number on success to indicate how many bytes have |
159 * been written; otherwise, an error code from <code>pp_errors.h</code>. | 191 * been written; otherwise, an error code from <code>pp_errors.h</code>. |
160 */ | 192 */ |
161 int32_t Write([in] PP_Resource tcp_socket, | 193 int32_t Write([in] PP_Resource tcp_socket, |
162 [in] str_t buffer, | 194 [in] str_t buffer, |
163 [in] int32_t bytes_to_write, | 195 [in] int32_t bytes_to_write, |
164 [in] PP_CompletionCallback callback); | 196 [in] PP_CompletionCallback callback); |
197 /** | |
198 * Starts listening. The socket must be bound and not connected. | |
199 * | |
200 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
201 * socket. | |
202 * @param[in] backlog A hint to determine the maximum length to which the | |
203 * queue of pending connections may grow. | |
204 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
205 * completion. | |
206 * | |
207 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | |
208 * including (but not limited to): | |
209 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required | |
210 * permissions. | |
211 * - <code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening | |
212 * on the same port. | |
213 */ | |
214 [version=1.1] | |
215 int32_t Listen([in] PP_Resource tcp_socket, | |
216 [in] int32_t backlog, | |
217 [in] PP_CompletionCallback callback); | |
165 | 218 |
166 /** | 219 /** |
167 * Cancels all pending reads and writes and disconnects the socket. Any | 220 * Accepts a connection. The socket must be listening. |
168 * pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> | 221 * |
169 * if pending IO was interrupted. After a call to this method, no output | 222 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
170 * buffer pointers passed into previous <code>Read()</code> calls will be | 223 * socket. |
171 * accessed. It is not valid to call <code>Connect()</code> again. | 224 * @param[out] accepted_tcp_socket Stores the accepted TCP socket on success. |
bbudge
2013/09/19 19:41:47
Is the returned socket bound and connected?
yzshen1
2013/09/19 21:12:15
Accepted socket is connected.
| |
225 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
226 * completion. | |
227 * | |
228 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | |
229 * including (but not limited to): | |
230 * - <code>PP_ERROR_CONNECTION_ABORTED</code>: A connection has been aborted. | |
231 */ | |
232 [version=1.1] | |
233 int32_t Accept([in] PP_Resource tcp_socket, | |
234 [out] PP_Resource accepted_tcp_socket, | |
235 [in] PP_CompletionCallback callback); | |
236 | |
237 /** | |
238 * Cancels all pending operations and closes the socket. Any pending callbacks | |
239 * will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was | |
240 * interrupted. After a call to this method, no output buffer pointers passed | |
241 * into previous <code>Read()</code> or <code>Accept()</code> calls will be | |
242 * accessed. It is not valid to call <code>Connect()</code> or | |
243 * <code>Listen()</code> again. | |
172 * | 244 * |
173 * The socket is implicitly closed if it is destroyed, so you are not required | 245 * The socket is implicitly closed if it is destroyed, so you are not required |
174 * to call this method. | 246 * to call this method. |
175 * | 247 * |
176 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 248 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
177 * socket. | 249 * socket. |
178 */ | 250 */ |
179 void Close([in] PP_Resource tcp_socket); | 251 void Close([in] PP_Resource tcp_socket); |
180 | 252 |
181 /** | 253 /** |
182 * Sets a socket option on the TCP socket. | 254 * Sets a socket option on the TCP socket. |
183 * Please see the <code>PP_TCPSocket_Option</code> description for option | 255 * Please see the <code>PP_TCPSocket_Option</code> description for option |
184 * names, value types and allowed values. | 256 * names, value types and allowed values. |
185 * | 257 * |
186 * @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 |
187 * socket. | 259 * socket. |
188 * @param[in] name The option to set. | 260 * @param[in] name The option to set. |
189 * @param[in] value The option value to set. | 261 * @param[in] value The option value to set. |
190 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 262 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
191 * completion. | 263 * completion. |
192 * | 264 * |
193 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 265 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
194 */ | 266 */ |
195 int32_t SetOption([in] PP_Resource tcp_socket, | 267 int32_t SetOption([in] PP_Resource tcp_socket, |
196 [in] PP_TCPSocket_Option name, | 268 [in] PP_TCPSocket_Option name, |
197 [in] PP_Var value, | 269 [in] PP_Var value, |
198 [in] PP_CompletionCallback callback); | 270 [in] PP_CompletionCallback callback); |
199 }; | 271 }; |
OLD | NEW |