OLD | NEW |
| (Empty) |
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 | |
3 * found in the LICENSE file. | |
4 */ | |
5 | |
6 /** | |
7 * This file defines the <code>PPB_TCPSocket_Dev</code> interface. | |
8 */ | |
9 | |
10 [generate_thunk] | |
11 | |
12 label Chrome { | |
13 M29 = 0.1 | |
14 }; | |
15 | |
16 /** | |
17 * Option names used by <code>SetOption()</code>. | |
18 */ | |
19 [assert_size(4)] | |
20 enum PP_TCPSocket_Option_Dev { | |
21 /** | |
22 * Disables coalescing of small writes to make TCP segments, and instead | |
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 */ | |
26 PP_TCPSOCKET_OPTION_NO_DELAY = 0, | |
27 | |
28 /** | |
29 * Specifies the total per-socket buffer space reserved for sends. Value's | |
30 * type should be <code>PP_VARTYPE_INT32</code>. | |
31 * This option can only be set after a successful <code>Connect()</code> call. | |
32 * | |
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 */ | |
37 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, | |
38 | |
39 /** | |
40 * Specifies the total per-socket buffer space reserved for receives. Value's | |
41 * type should be <code>PP_VARTYPE_INT32</code>. | |
42 * This option can only be set after a successful <code>Connect()</code> call. | |
43 * | |
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 */ | |
48 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 | |
49 }; | |
50 | |
51 /** | |
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 | |
58 */ | |
59 interface PPB_TCPSocket_Dev { | |
60 /** | |
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. | |
68 */ | |
69 PP_Resource Create([in] PP_Instance instance); | |
70 | |
71 /** | |
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. | |
79 */ | |
80 PP_Bool IsTCPSocket([in] PP_Resource resource); | |
81 | |
82 /** | |
83 * Connects the socket to the given address. | |
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</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. | |
102 */ | |
103 int32_t Connect([in] PP_Resource tcp_socket, | |
104 [in] PP_Resource addr, | |
105 [in] PP_CompletionCallback callback); | |
106 | |
107 /** | |
108 * Gets the local address of the socket, if it is connected. | |
109 * | |
110 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
111 * socket. | |
112 * | |
113 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. | |
114 */ | |
115 PP_Resource GetLocalAddress([in] PP_Resource tcp_socket); | |
116 | |
117 /** | |
118 * Gets the remote address of the socket, if it is connected. | |
119 * | |
120 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
121 * socket. | |
122 * | |
123 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. | |
124 */ | |
125 PP_Resource GetRemoteAddress([in] PP_Resource tcp_socket); | |
126 | |
127 /** | |
128 * Reads data from the socket. The socket must be connected. It may perform a | |
129 * partial read. | |
130 * | |
131 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
132 * socket. | |
133 * @param[out] buffer The buffer to store the received data on success. It | |
134 * must be at least as large as <code>bytes_to_read</code>. | |
135 * @param[in] bytes_to_read The number of bytes to read. | |
136 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
137 * completion. | |
138 * | |
139 * @return A non-negative number on success to indicate how many bytes have | |
140 * been read, 0 means that end-of-file was reached; otherwise, an error code | |
141 * from <code>pp_errors.h</code>. | |
142 */ | |
143 int32_t Read([in] PP_Resource tcp_socket, | |
144 [out] str_t buffer, | |
145 [in] int32_t bytes_to_read, | |
146 [in] PP_CompletionCallback callback); | |
147 | |
148 /** | |
149 * Writes data to the socket. The socket must be connected. It may perform a | |
150 * partial write. | |
151 * | |
152 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
153 * socket. | |
154 * @param[in] buffer The buffer containing the data to write. | |
155 * @param[in] bytes_to_write The number of bytes to write. | |
156 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
157 * completion. | |
158 * | |
159 * @return A non-negative number on success to indicate how many bytes have | |
160 * been written; otherwise, an error code from <code>pp_errors.h</code>. | |
161 */ | |
162 int32_t Write([in] PP_Resource tcp_socket, | |
163 [in] str_t buffer, | |
164 [in] int32_t bytes_to_write, | |
165 [in] PP_CompletionCallback callback); | |
166 | |
167 /** | |
168 * Cancels all pending reads and writes and disconnects the socket. Any | |
169 * pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> | |
170 * if pending IO was interrupted. After a call to this method, no output | |
171 * buffer pointers passed into previous <code>Read()</code> calls will be | |
172 * accessed. It is not valid to call <code>Connect()</code> again. | |
173 * | |
174 * The socket is implicitly closed if it is destroyed, so you are not required | |
175 * to call this method. | |
176 * | |
177 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
178 * socket. | |
179 */ | |
180 void Close([in] PP_Resource tcp_socket); | |
181 | |
182 /** | |
183 * Sets a socket option on the TCP socket. | |
184 * Please see the <code>PP_TCPSocket_Option_Dev</code> description for option | |
185 * names, value types and allowed values. | |
186 * | |
187 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP | |
188 * socket. | |
189 * @param[in] name The option to set. | |
190 * @param[in] value The option value to set. | |
191 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
192 * completion. | |
193 * | |
194 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
195 */ | |
196 int32_t SetOption([in] PP_Resource tcp_socket, | |
197 [in] PP_TCPSocket_Option_Dev name, | |
198 [in] PP_Var value, | |
199 [in] PP_CompletionCallback callback); | |
200 }; | |
OLD | NEW |