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 names used by <code>SetOption()</code>. |
| 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 |
20 // This option can only be set after a successful Connect() call. | 23 * delivers data immediately. Value's type is <code>PP_VARTYPE_BOOL</code>. |
| 24 * This option can only be set after a successful <code>Connect()</code> call. |
| 25 */ |
21 PP_TCPSOCKET_OPTION_NO_DELAY = 0, | 26 PP_TCPSOCKET_OPTION_NO_DELAY = 0, |
22 | 27 |
23 // Specifies the socket send buffer in bytes. Value's type should be | 28 /** |
24 // PP_VARTYPE_INT32. | 29 * Specifies the total per-socket buffer space reserved for sends. Value's |
25 // This option can only be set after a successful Connect() call. | 30 * type should be <code>PP_VARTYPE_INT32</code>. |
26 // Note: This is only treated as a hint for the browser to set the buffer | 31 * This option can only be set after a successful <code>Connect()</code> call. |
27 // size. Even if SetOption() reports that this option has been successfully | 32 * |
28 // set, the browser doesn't guarantee to conform to it. | 33 * Note: This is only treated as a hint for the browser to set the buffer |
| 34 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't |
| 35 * guarantee it will conform to the size. |
| 36 */ |
29 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, | 37 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, |
30 | 38 |
31 // Specifies the socket receive buffer in bytes. Value's type should be | 39 /** |
32 // PP_VARTYPE_INT32. | 40 * Specifies the total per-socket buffer space reserved for receives. Value's |
33 // This option can only be set after a successful Connect() call. | 41 * type should be <code>PP_VARTYPE_INT32</code>. |
34 // Note: This is only treated as a hint for the browser to set the buffer | 42 * This option can only be set after a successful <code>Connect()</code> call. |
35 // size. Even if SetOption() reports that this option has been successfully | 43 * |
36 // set, the browser doesn't guarantee to conform to it. | 44 * 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 |
| 46 * guarantee it will conform to the size. |
| 47 */ |
37 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 | 48 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 |
38 }; | 49 }; |
39 | 50 |
40 /** | 51 /** |
41 * 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 |
42 */ | 58 */ |
43 interface PPB_TCPSocket_Dev { | 59 interface PPB_TCPSocket_Dev { |
44 /** | 60 /** |
45 * 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. |
46 */ | 68 */ |
47 PP_Resource Create([in] PP_Instance instance); | 69 PP_Resource Create([in] PP_Instance instance); |
48 | 70 |
49 /** | 71 /** |
50 * 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. |
51 */ | 79 */ |
52 PP_Bool IsTCPSocket([in] PP_Resource resource); | 80 PP_Bool IsTCPSocket([in] PP_Resource resource); |
53 | 81 |
54 /** | 82 /** |
55 * Connects to an address given by |addr|, which is a PPB_NetAddress_Dev | 83 * Connects the socket to the given address. |
56 * 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. |
57 */ | 102 */ |
58 int32_t Connect([in] PP_Resource tcp_socket, | 103 int32_t Connect([in] PP_Resource tcp_socket, |
59 [in] PP_Resource addr, | 104 [in] PP_Resource addr, |
60 [in] PP_CompletionCallback callback); | 105 [in] PP_CompletionCallback callback); |
61 | 106 |
62 /** | 107 /** |
63 * Gets the local address of the socket, if it has been connected. | 108 * Gets the local address of the socket, if it is connected. |
64 * 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. |
65 */ | 115 */ |
66 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); | 116 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); |
67 | 117 |
68 /** | 118 /** |
69 * Gets the remote address of the socket, if it has been connected. | 119 * Gets the remote address of the socket, if it is connected. |
70 * 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. |
71 */ | 126 */ |
72 PP_Resource GetRemoteAddress([in] PP_Resource tcp_socket); | 127 PP_Resource GetRemoteAddress([in] PP_Resource tcp_socket); |
73 | 128 |
74 /** | 129 /** |
75 * Reads data from the socket. The size of |buffer| must be at least as large | 130 * Reads data from the socket. The socket must be connected. It may perform a |
76 * as |bytes_to_read|. May perform a partial read. Returns the number of bytes | 131 * partial read. |
77 * read or an error code. If the return value is 0, then it indicates that | |
78 * end-of-file was reached. | |
79 * | 132 * |
80 * 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>. |
81 */ | 144 */ |
82 int32_t Read([in] PP_Resource tcp_socket, | 145 int32_t Read([in] PP_Resource tcp_socket, |
83 [out] str_t buffer, | 146 [out] str_t buffer, |
84 [in] int32_t bytes_to_read, | 147 [in] int32_t bytes_to_read, |
85 [in] PP_CompletionCallback callback); | 148 [in] PP_CompletionCallback callback); |
86 | 149 |
87 /** | 150 /** |
88 * Writes data to the socket. May perform a partial write. Returns the number | 151 * Writes data to the socket. The socket must be connected. It may perform a |
89 * of bytes written or an error code. | 152 * partial write. |
90 * | 153 * |
91 * 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>. |
92 */ | 163 */ |
93 int32_t Write([in] PP_Resource tcp_socket, | 164 int32_t Write([in] PP_Resource tcp_socket, |
94 [in] str_t buffer, | 165 [in] str_t buffer, |
95 [in] int32_t bytes_to_write, | 166 [in] int32_t bytes_to_write, |
96 [in] PP_CompletionCallback callback); | 167 [in] PP_CompletionCallback callback); |
97 | 168 |
98 /** | 169 /** |
99 * Cancels any IO that may be pending, and disconnects the socket. Any pending | 170 * Cancels all pending reads and writes and disconnects the socket. Any |
100 * callbacks will still run, reporting PP_ERROR_ABORTED if pending IO was | 171 * pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> |
101 * interrupted. It is NOT valid to call Connect() again after a call to this | 172 * if pending IO was interrupted. After a call to this method, no output |
102 * method. Note: If the socket is destroyed when it is still connected, then | 173 * buffer pointers passed into previous <code>Read()</code> calls will be |
103 * it will be implicitly disconnected, so you are not required to call this | 174 * accessed. It is not valid to call <code>Connect()</code> again. |
104 * 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. |
105 */ | 181 */ |
106 void Close([in] PP_Resource tcp_socket); | 182 void Close([in] PP_Resource tcp_socket); |
107 | 183 |
108 /** | 184 /** |
109 * Sets an option on |tcp_socket|. Supported |name| and |value| parameters | 185 * Sets a socket option on the TCP socket. |
110 * are as described for PP_TCPSocketOption_Dev. |callback| will be | 186 * Please see the <code>PP_TCPSocket_Option_Dev</code> description for option |
111 * invoked with PP_OK if setting the option succeeds, or an error code | 187 * names, value types and allowed values. |
112 * otherwise. | 188 * |
| 189 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 190 * socket. |
| 191 * @param[in] name The option 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>. |
113 */ | 197 */ |
114 int32_t SetOption([in] PP_Resource tcp_socket, | 198 int32_t SetOption([in] PP_Resource tcp_socket, |
115 [in] PP_TCPSocket_Option_Dev name, | 199 [in] PP_TCPSocket_Option_Dev name, |
116 [in] PP_Var value, | 200 [in] PP_Var value, |
117 [in] PP_CompletionCallback callback); | 201 [in] PP_CompletionCallback callback); |
118 }; | 202 }; |
OLD | NEW |