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_Dev</code> interface. | 7 * This file defines the <code>PPB_TCPSocket_Dev</code> interface. |
8 */ | 8 */ |
9 | 9 |
10 [generate_thunk] | 10 [generate_thunk] |
11 | 11 |
12 label Chrome { | 12 label Chrome { |
13 M29 = 0.1 | 13 M29 = 0.1 |
14 }; | 14 }; |
15 | 15 |
16 /** | |
17 * Option types used by <code>SetOption()</code>. | |
bbudge
2013/06/20 17:38:27
s/types/names
yzshen1
2013/06/20 20:27:45
Done.
| |
18 */ | |
16 [assert_size(4)] | 19 [assert_size(4)] |
17 enum PP_TCPSocket_Option_Dev { | 20 enum PP_TCPSocket_Option_Dev { |
18 // Disables coalescing of small writes to make TCP segments, and instead | 21 /** |
19 // deliver data immediately. Value type is PP_VARTYPE_BOOL. | 22 * Disables coalescing of small writes to make TCP segments, and instead |
bbudge
2013/06/20 17:38:27
s/Disables/Disable
this is to match 'deliver' late
yzshen1
2013/06/20 20:27:45
May I change 'deliver' to 'delivers'?
We usually u
bbudge
2013/06/20 21:02:32
OK
| |
23 * deliver data immediately. Value type is <code>PP_VARTYPE_BOOL</code>. | |
bbudge
2013/06/20 17:38:27
s/Value type is/Value's type should be
to match UD
yzshen1
2013/06/20 20:27:45
Done.
| |
24 * This option can only be set after a successful <code>Connect()</code> call. | |
25 */ | |
20 PP_TCPSOCKET_OPTION_NO_DELAY = 0, | 26 PP_TCPSOCKET_OPTION_NO_DELAY = 0, |
21 | 27 |
22 // Specifies the socket send buffer in bytes. Value's type should be | 28 /** |
23 // PP_VARTYPE_INT32. | 29 * Specifies the socket send buffer in bytes. Value's type should be |
bbudge
2013/06/20 17:38:27
nit s/buffer/buffer size
Here and below. Or better
yzshen1
2013/06/20 20:27:45
Done.
| |
24 // Note: This is only treated as a hint for the browser to set the buffer | 30 * <code>PP_VARTYPE_INT32</code>. |
25 // size. Even if SetOption() reports that this option has been successfully | 31 * This option can only be set after a successful <code>Connect()</code> call. |
26 // set, the browser doesn't guarantee to conform to it. | 32 * |
33 * Note: This is only treated as a hint for the browser to set the buffer | |
34 * size. Even if <code>SetOption()</code> reports that this option has been | |
35 * successfully set, the browser doesn't guarantee to conform to it. | |
bbudge
2013/06/20 17:38:27
s/to/it will
yzshen1
2013/06/20 20:27:45
Done.
| |
36 */ | |
27 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, | 37 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, |
28 | 38 |
29 // Specifies the socket receive buffer in bytes. Value's type should be | 39 /** |
30 // PP_VARTYPE_INT32. | 40 * Specifies the socket receive buffer in bytes. Value's type should be |
31 // Note: This is only treated as a hint for the browser to set the buffer | 41 * <code>PP_VARTYPE_INT32</code>. |
32 // size. Even if SetOption() reports that this option has been successfully | 42 * This option can only be set after a successful <code>Connect()</code> call. |
33 // set, the browser doesn't guarantee to conform to it. | 43 * |
44 * Note: This is only treated as a hint for the browser to set the buffer | |
45 * size. Even if <code>SetOption()</code> reports that this option has been | |
46 * successfully set, the browser doesn't guarantee to conform to it. | |
bbudge
2013/06/20 17:38:27
s/to/it will
yzshen1
2013/06/20 20:27:45
Done.
| |
47 */ | |
34 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 | 48 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 |
35 }; | 49 }; |
36 | 50 |
37 /** | 51 /** |
38 * The <code>PPB_TCPSocket_Dev</code> interface provides TCP socket operations. | 52 * The <code>PPB_TCPSocket_Dev</code> interface provides TCP socket operations. |
53 * | |
54 * Permissions: Apps permission <code>socket</code> with subrule | |
55 * <code>tcp-connect</code> is required for <code>Connect()</code>. | |
56 * For more details about network communication permissions, please see: | |
57 * http://developer.chrome.com/apps/app_network.html | |
39 */ | 58 */ |
40 interface PPB_TCPSocket_Dev { | 59 interface PPB_TCPSocket_Dev { |
41 /** | 60 /** |
42 * Allocates a TCP socket resource. | 61 * Creates a TCP socket resource. |
62 * | |
63 * @param[in] instance A <code>PP_Instance</code> identifying one instance of | |
64 * a module. | |
65 * | |
66 * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0 | |
67 * on failure. | |
43 */ | 68 */ |
44 PP_Resource Create([in] PP_Instance instance); | 69 PP_Resource Create([in] PP_Instance instance); |
45 | 70 |
46 /** | 71 /** |
47 * Determines if a given resource is TCP socket. | 72 * Determines if a given resource is a TCP socket. |
73 * | |
74 * @param[in] resource A <code>PP_Resource</code> to check. | |
75 * | |
76 * @return <code>PP_TRUE</code> if the input is a | |
77 * <code>PPB_TCPSocket_Dev</code> resource; <code>PP_FALSE</code> | |
78 * otherwise. | |
48 */ | 79 */ |
49 PP_Bool IsTCPSocket([in] PP_Resource resource); | 80 PP_Bool IsTCPSocket([in] PP_Resource resource); |
50 | 81 |
51 /** | 82 /** |
52 * Connects to an address given by |addr|, which is a PPB_NetAddress_Dev | 83 * Connects to the given address. |
53 * resource. | 84 * |
85 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
86 * socket. | |
87 * @param[in] addr A <code>PPB_NetAddress_Dev</code> resource. | |
88 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
89 * completion. | |
90 * | |
91 * @return An int32_t containing an error code from <code>pp_errors.h</code>, | |
92 * including (but not limited to): | |
93 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required | |
94 * permissions. | |
95 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is | |
96 * unreachable. | |
97 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was | |
98 * refused. | |
99 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. | |
100 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed | |
101 * out. | |
54 */ | 102 */ |
55 int32_t Connect([in] PP_Resource tcp_socket, | 103 int32_t Connect([in] PP_Resource tcp_socket, |
56 [in] PP_Resource addr, | 104 [in] PP_Resource addr, |
57 [in] PP_CompletionCallback callback); | 105 [in] PP_CompletionCallback callback); |
58 | 106 |
59 /** | 107 /** |
60 * Gets the local address of the socket, if it has been connected. | 108 * Gets the local address of the socket, if it has been connected. |
61 * Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure. | 109 * |
110 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
111 * socket. | |
112 * | |
113 * @return A <code>PPB_NetAddress_Dev</code> resource on success or 0 on | |
114 * failure. | |
62 */ | 115 */ |
63 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); | 116 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); |
64 | 117 |
65 /** | 118 /** |
66 * Gets the remote address of the socket, if it has been connected. | 119 * Gets the remote address of the socket, if it has been connected. |
67 * Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure. | 120 * |
121 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
122 * socket. | |
123 * | |
124 * @return A <code>PPB_NetAddress_Dev</code> resource on success or 0 on | |
125 * failure. | |
68 */ | 126 */ |
69 PP_Resource GetRemoteAddress([in] PP_Resource tcp_socket); | 127 PP_Resource GetRemoteAddress([in] PP_Resource tcp_socket); |
70 | 128 |
71 /** | 129 /** |
72 * Reads data from the socket. The size of |buffer| must be at least as large | 130 * Reads data from the socket. It can only be called after a successful |
bbudge
2013/06/20 17:38:27
s/It can/It should
because you can call it, but it
yzshen1
2013/06/20 20:27:45
I have changed to "the socket must be connected" a
| |
73 * as |bytes_to_read|. May perform a partial read. Returns the number of bytes | 131 * <code>Connect()</code> call. It may perform a partial read. |
74 * read or an error code. If the return value is 0, then it indicates that | |
75 * end-of-file was reached. | |
76 * | 132 * |
77 * Multiple outstanding read requests are not supported. | 133 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
134 * socket. | |
135 * @param[out] buffer The buffer to store the received data on success. It | |
136 * must be at least as large as <code>bytes_to_read</code>. | |
137 * @param[in] bytes_to_read The number of bytes to read. | |
138 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
139 * completion. | |
140 * | |
141 * @return A non-negative number on success to indicate how many bytes have | |
142 * been read, 0 means that end-of-file was reached; otherwise, an error code | |
143 * from <code>pp_errors.h</code>. | |
78 */ | 144 */ |
79 int32_t Read([in] PP_Resource tcp_socket, | 145 int32_t Read([in] PP_Resource tcp_socket, |
80 [out] str_t buffer, | 146 [out] str_t buffer, |
81 [in] int32_t bytes_to_read, | 147 [in] int32_t bytes_to_read, |
82 [in] PP_CompletionCallback callback); | 148 [in] PP_CompletionCallback callback); |
83 | 149 |
84 /** | 150 /** |
85 * Writes data to the socket. May perform a partial write. Returns the number | 151 * Writes data to the socket. It can only be called after a successful |
bbudge
2013/06/20 17:38:27
s/It can/It should
yzshen1
2013/06/20 20:27:45
I have changed to "the socket must be connected" a
| |
86 * of bytes written or an error code. | 152 * <code>Connect()</code> call. It may perform a partial write. |
87 * | 153 * |
88 * Multiple outstanding write requests are not supported. | 154 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
155 * socket. | |
156 * @param[in] buffer The buffer containing the data to write. | |
157 * @param[in] bytes_to_write The number of bytes to write. | |
158 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
159 * completion. | |
160 * | |
161 * @return A non-negative number on success to indicate how many bytes have | |
162 * been written; otherwise, an error code from <code>pp_errors.h</code>. | |
89 */ | 163 */ |
90 int32_t Write([in] PP_Resource tcp_socket, | 164 int32_t Write([in] PP_Resource tcp_socket, |
91 [in] str_t buffer, | 165 [in] str_t buffer, |
92 [in] int32_t bytes_to_write, | 166 [in] int32_t bytes_to_write, |
93 [in] PP_CompletionCallback callback); | 167 [in] PP_CompletionCallback callback); |
94 | 168 |
95 /** | 169 /** |
96 * Cancels any IO that may be pending, and disconnects the socket. Any pending | 170 * Cancels all pending reads and writes, disconnects the socket. Any pending |
bbudge
2013/06/20 17:38:27
s/,/and
yzshen1
2013/06/20 20:27:45
Done.
| |
97 * callbacks will still run, reporting PP_ERROR_ABORTED if pending IO was | 171 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if |
98 * interrupted. It is NOT valid to call Connect() again after a call to this | 172 * pending IO was interrupted. After a call to this method, any output buffers |
bbudge
2013/06/20 17:38:27
A little awkward. How about:
After a call to this
yzshen1
2013/06/20 20:27:45
yeah, it sounds much better. Thanks!
On 2013/06/20
| |
99 * method. Note: If the socket is destroyed when it is still connected, then | 173 * passed into previous <code>Read()</code> calls won't be accessed. It is |
100 * it will be implicitly disconnected, so you are not required to call this | 174 * not valid to call <code>Connect()</code> again. |
101 * method. | 175 * |
176 * The socket is implicitly closed if it is destroyed, so you are not required | |
177 * to call this method. | |
178 * | |
179 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
180 * socket. | |
102 */ | 181 */ |
103 void Close([in] PP_Resource tcp_socket); | 182 void Close([in] PP_Resource tcp_socket); |
104 | 183 |
105 /** | 184 /** |
106 * Sets an option on |tcp_socket|. Supported |name| and |value| parameters | 185 * Sets a socket option on the TCP socket. |
107 * are as described for PP_TCPSocketOption_Dev. |callback| will be | 186 * Please see the <code>PP_TCPSocket_Option_Dev</code> description for option |
108 * invoked with PP_OK if setting the option succeeds, or an error code | 187 * names, value types and allowed values. |
109 * otherwise. The socket must be connected before SetOption is called. | 188 * |
189 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
190 * socket. | |
191 * @param[in] name The option type to set. | |
192 * @param[in] value The option value to set. | |
193 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
194 * completion. | |
195 * | |
196 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
110 */ | 197 */ |
111 int32_t SetOption([in] PP_Resource tcp_socket, | 198 int32_t SetOption([in] PP_Resource tcp_socket, |
112 [in] PP_TCPSocket_Option_Dev name, | 199 [in] PP_TCPSocket_Option_Dev name, |
113 [in] PP_Var value, | 200 [in] PP_Var value, |
114 [in] PP_CompletionCallback callback); | 201 [in] PP_CompletionCallback callback); |
115 }; | 202 }; |
OLD | NEW |