Chromium Code Reviews| 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 /** |
| 80 * Creates a TCP socket resource. | |
| 81 * | |
| 82 * @param[in] instance A <code>PP_Instance</code> identifying one instance of | |
| 83 * a module. | |
| 84 * @param[in] faimly The address family type for the socket. | |
|
bbudge
2013/09/17 19:42:18
s/faimly/family
yzshen1
2013/09/18 16:56:26
Done.
| |
| 85 * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0 | |
| 86 * on failure. | |
| 87 */ | |
| 88 [version=1.1] | |
| 89 PP_Resource Create([in] PP_Instance instance, | |
| 90 [in] PP_NetAddress_Family family); | |
|
yzshen1
2013/09/17 18:30:58
This is needed to create the underlying OS socket.
bbudge
2013/09/17 19:42:18
Is there any way that address family could be spec
noelallen1
2013/09/18 04:08:51
tcp::Create(inst, family) = socket(family, SOCK_ST
yzshen1
2013/09/18 16:56:26
I agree with Noel here. It seems natural to have f
bbudge
2013/09/18 17:46:35
I was looking at the API without considering imple
yzshen1
2013/09/18 18:06:56
IMO, it seems unusual to most POSIX develop to con
| |
| 91 | |
| 92 /** | |
| 72 * Determines if a given resource is a TCP socket. | 93 * Determines if a given resource is a TCP socket. |
| 73 * | 94 * |
| 74 * @param[in] resource A <code>PP_Resource</code> to check. | 95 * @param[in] resource A <code>PP_Resource</code> to check. |
| 75 * | 96 * |
| 76 * @return <code>PP_TRUE</code> if the input is a | 97 * @return <code>PP_TRUE</code> if the input is a |
| 77 * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise. | 98 * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise. |
| 78 */ | 99 */ |
| 79 PP_Bool IsTCPSocket([in] PP_Resource resource); | 100 PP_Bool IsTCPSocket([in] PP_Resource resource); |
| 80 | 101 |
| 81 /** | 102 /** |
| 82 * Connects the socket to the given address. | 103 * Binds the socket to the given address. The socket must not be bound. |
| 83 * | 104 * |
| 84 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 105 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 85 * socket. | 106 * socket. |
| 107 * @param[in] addr A <code>PPB_NetAddress</code> resource. | |
| 108 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
| 109 * completion. | |
| 110 * | |
| 111 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | |
| 112 * including (but not limited to): | |
| 113 * - <code>PP_ERROR_ADDRESS_IN_USE</code>: the address is already in use. | |
| 114 * - <code>PP_ERROR_ADDRESS_INVALID</code>: the address is invalid. | |
| 115 */ | |
| 116 [version=1.1] | |
| 117 int32_t Bind([in] PP_Resource tcp_socket, | |
| 118 [in] PP_Resource addr, | |
| 119 [in] PP_CompletionCallback callback); | |
| 120 | |
| 121 /** | |
| 122 * Connects the socket to the given address. The socket must not be listening. | |
| 123 * | |
| 124 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
| 125 * socket. | |
| 86 * @param[in] addr A <code>PPB_NetAddress</code> resource. | 126 * @param[in] addr A <code>PPB_NetAddress</code> resource. |
| 87 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 127 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 88 * completion. | 128 * completion. |
| 89 * | 129 * |
| 90 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | 130 * @return An int32_t containing an error code from <code>pp_errors.h</code>, |
| 91 * including (but not limited to): | 131 * including (but not limited to): |
| 92 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required | 132 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required |
| 93 * permissions. | 133 * permissions. |
| 94 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is | 134 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is |
| 95 * unreachable. | 135 * unreachable. |
| 96 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was | 136 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was |
| 97 * refused. | 137 * refused. |
| 98 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. | 138 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. |
| 99 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed | 139 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed |
| 100 * out. | 140 * out. |
| 141 * | |
| 142 * If the socket is listening/connected or has a pending listen/connect | |
| 143 * request, <code>Connect()</code> will fail without starting a connection | |
| 144 * attempt. Otherwise, any failure during the connection attempt will cause | |
| 145 * the socket to be closed. | |
|
yzshen1
2013/09/17 18:30:58
According to POSIX:
"""If connect() fails, the sta
bbudge
2013/09/17 19:42:18
This seems OK to me. We can add this capability la
| |
| 101 */ | 146 */ |
| 102 int32_t Connect([in] PP_Resource tcp_socket, | 147 int32_t Connect([in] PP_Resource tcp_socket, |
| 103 [in] PP_Resource addr, | 148 [in] PP_Resource addr, |
| 104 [in] PP_CompletionCallback callback); | 149 [in] PP_CompletionCallback callback); |
| 105 | 150 |
| 106 /** | 151 /** |
| 107 * Gets the local address of the socket, if it is connected. | 152 * Gets the local address of the socket, if it is bound. |
| 108 * | 153 * |
| 109 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 154 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 110 * socket. | 155 * socket. |
| 111 * | 156 * |
| 112 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. | 157 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. |
| 113 */ | 158 */ |
| 114 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); | 159 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); |
| 115 | 160 |
| 116 /** | 161 /** |
| 117 * Gets the remote address of the socket, if it is connected. | 162 * 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 | 200 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 156 * completion. | 201 * completion. |
| 157 * | 202 * |
| 158 * @return A non-negative number on success to indicate how many bytes have | 203 * @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>. | 204 * been written; otherwise, an error code from <code>pp_errors.h</code>. |
| 160 */ | 205 */ |
| 161 int32_t Write([in] PP_Resource tcp_socket, | 206 int32_t Write([in] PP_Resource tcp_socket, |
| 162 [in] str_t buffer, | 207 [in] str_t buffer, |
| 163 [in] int32_t bytes_to_write, | 208 [in] int32_t bytes_to_write, |
| 164 [in] PP_CompletionCallback callback); | 209 [in] PP_CompletionCallback callback); |
| 210 /** | |
| 211 * Starts listening. The socket must be bound and not connected. | |
| 212 * | |
| 213 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
| 214 * socket. | |
| 215 * @param[in] backlog A hint to determine the maximum length to which the | |
| 216 * queue of pending connections may grow. | |
| 217 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
| 218 * completion. | |
| 219 * | |
| 220 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | |
| 221 * including (but not limited to): | |
| 222 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required | |
| 223 * permissions. | |
| 224 * - <code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening | |
| 225 * on the same port. | |
| 226 */ | |
| 227 [version=1.1] | |
| 228 int32_t Listen([in] PP_Resource tcp_socket, | |
| 229 [in] int32_t backlog, | |
| 230 [in] PP_CompletionCallback callback); | |
| 165 | 231 |
| 166 /** | 232 /** |
| 167 * Cancels all pending reads and writes and disconnects the socket. Any | 233 * Accepts a connection. The socket must be listening. |
| 168 * pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> | 234 * |
| 169 * if pending IO was interrupted. After a call to this method, no output | 235 * @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 | 236 * socket. |
| 171 * accessed. It is not valid to call <code>Connect()</code> again. | 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 [version=1.1] | |
| 246 int32_t Accept([in] PP_Resource tcp_socket, | |
| 247 [out] PP_Resource accepted_tcp_socket, | |
| 248 [in] PP_CompletionCallback callback); | |
| 249 | |
| 250 /** | |
| 251 * Cancels all pending operations and closes the socket. Any pending callbacks | |
| 252 * will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was | |
| 253 * interrupted. After a call to this method, no output buffer pointers passed | |
| 254 * into previous <code>Read()</code> or <code>Accept()</code> calls will be | |
| 255 * accessed. It is not valid to call <code>Connect()</code> or | |
| 256 * <code>Listen()</code> again. | |
| 172 * | 257 * |
| 173 * The socket is implicitly closed if it is destroyed, so you are not required | 258 * The socket is implicitly closed if it is destroyed, so you are not required |
| 174 * to call this method. | 259 * to call this method. |
| 175 * | 260 * |
| 176 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 261 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 177 * socket. | 262 * socket. |
| 178 */ | 263 */ |
| 179 void Close([in] PP_Resource tcp_socket); | 264 void Close([in] PP_Resource tcp_socket); |
| 180 | 265 |
| 181 /** | 266 /** |
| 182 * Sets a socket option on the TCP socket. | 267 * Sets a socket option on the TCP socket. |
| 183 * Please see the <code>PP_TCPSocket_Option</code> description for option | 268 * Please see the <code>PP_TCPSocket_Option</code> description for option |
| 184 * names, value types and allowed values. | 269 * names, value types and allowed values. |
| 185 * | 270 * |
| 186 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | 271 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 187 * socket. | 272 * socket. |
| 188 * @param[in] name The option to set. | 273 * @param[in] name The option to set. |
| 189 * @param[in] value The option value to set. | 274 * @param[in] value The option value to set. |
| 190 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | 275 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 191 * completion. | 276 * completion. |
| 192 * | 277 * |
| 193 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | 278 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 194 */ | 279 */ |
| 195 int32_t SetOption([in] PP_Resource tcp_socket, | 280 int32_t SetOption([in] PP_Resource tcp_socket, |
| 196 [in] PP_TCPSocket_Option name, | 281 [in] PP_TCPSocket_Option name, |
| 197 [in] PP_Var value, | 282 [in] PP_Var value, |
| 198 [in] PP_CompletionCallback callback); | 283 [in] PP_CompletionCallback callback); |
| 199 }; | 284 }; |
| OLD | NEW |