Fix build break
[chromium-blink-merge.git] / ppapi / c / private / ppb_tcp_socket_private.h
blob6aad46750a88aa31d46a38fb706801d84461e67d
1 /* Copyright (c) 2012 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 */
6 /* From private/ppb_tcp_socket_private.idl modified Sun Feb 10 00:28:07 2013. */
8 #ifndef PPAPI_C_PRIVATE_PPB_TCP_SOCKET_PRIVATE_H_
9 #define PPAPI_C_PRIVATE_PPB_TCP_SOCKET_PRIVATE_H_
11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_macros.h"
15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/pp_stdint.h"
17 #include "ppapi/c/pp_var.h"
18 #include "ppapi/c/private/ppb_net_address_private.h"
20 #define PPB_TCPSOCKET_PRIVATE_INTERFACE_0_3 "PPB_TCPSocket_Private;0.3"
21 #define PPB_TCPSOCKET_PRIVATE_INTERFACE_0_4 "PPB_TCPSocket_Private;0.4"
22 #define PPB_TCPSOCKET_PRIVATE_INTERFACE_0_5 "PPB_TCPSocket_Private;0.5"
23 #define PPB_TCPSOCKET_PRIVATE_INTERFACE PPB_TCPSOCKET_PRIVATE_INTERFACE_0_5
25 /**
26 * @file
27 * This file defines the <code>PPB_TCPSocket_Private</code> interface.
31 /**
32 * @addtogroup Enums
33 * @{
35 typedef enum {
36 /* Special value used for testing. Guaranteed to fail SetOption(). */
37 PP_TCPSOCKETOPTION_INVALID = 0,
38 /* Disable coalescing of small writes to make TCP segments, and instead
39 * deliver data immediately. For SSL sockets, this option must be set before
40 * SSLHandshake() is called. Value type is PP_VARTYPE_BOOL. */
41 PP_TCPSOCKETOPTION_NO_DELAY = 1
42 } PP_TCPSocketOption_Private;
43 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocketOption_Private, 4);
44 /**
45 * @}
48 /**
49 * @addtogroup Interfaces
50 * @{
52 /**
53 * The <code>PPB_TCPSocket_Private</code> interface provides TCP socket
54 * operations.
56 struct PPB_TCPSocket_Private_0_5 {
57 /**
58 * Allocates a TCP socket resource.
60 PP_Resource (*Create)(PP_Instance instance);
61 /**
62 * Determines if a given resource is TCP socket.
64 PP_Bool (*IsTCPSocket)(PP_Resource resource);
65 /**
66 * Connects to a TCP port given as a host-port pair.
67 * When a proxy server is used, |host| and |port| refer to the proxy server
68 * instead of the destination server.
70 int32_t (*Connect)(PP_Resource tcp_socket,
71 const char* host,
72 uint16_t port,
73 struct PP_CompletionCallback callback);
74 /**
75 * Same as Connect(), but connecting to the address given by |addr|. A typical
76 * use-case would be for reconnections.
78 int32_t (*ConnectWithNetAddress)(PP_Resource tcp_socket,
79 const struct PP_NetAddress_Private* addr,
80 struct PP_CompletionCallback callback);
81 /**
82 * Gets the local address of the socket, if it has been connected.
83 * Returns PP_TRUE on success.
85 PP_Bool (*GetLocalAddress)(PP_Resource tcp_socket,
86 struct PP_NetAddress_Private* local_addr);
87 /**
88 * Gets the remote address of the socket, if it has been connected.
89 * Returns PP_TRUE on success.
91 PP_Bool (*GetRemoteAddress)(PP_Resource tcp_socket,
92 struct PP_NetAddress_Private* remote_addr);
93 /**
94 * Does SSL handshake and moves to sending and receiving encrypted data. The
95 * socket must have been successfully connected. |server_name| will be
96 * compared with the name(s) in the server's certificate during the SSL
97 * handshake. |server_port| is only used to identify an SSL server in the SSL
98 * session cache.
99 * When a proxy server is used, |server_name| and |server_port| refer to the
100 * destination server.
101 * If the socket is not connected, or there are pending read/write requests,
102 * SSLHandshake() will fail without starting a handshake. Otherwise, any
103 * failure during the handshake process will cause the socket to be
104 * disconnected.
106 int32_t (*SSLHandshake)(PP_Resource tcp_socket,
107 const char* server_name,
108 uint16_t server_port,
109 struct PP_CompletionCallback callback);
111 * Returns the server's <code>PPB_X509Certificate_Private</code> for a socket
112 * connection if an SSL connection has been established using
113 * <code>SSLHandshake</code>. If no SSL connection has been established, a
114 * null resource is returned.
116 PP_Resource (*GetServerCertificate)(PP_Resource tcp_socket);
118 * NOTE: This function is not implemented and will return
119 * <code>PP_FALSE</code>.
120 * Adds a trusted/untrusted chain building certificate to be used for this
121 * connection. The <code>certificate</code> must be a
122 * <code>PPB_X509Certificate_Private<code>. <code>PP_TRUE</code> is returned
123 * upon success.
125 PP_Bool (*AddChainBuildingCertificate)(PP_Resource tcp_socket,
126 PP_Resource certificate,
127 PP_Bool is_trusted);
129 * Reads data from the socket. The size of |buffer| must be at least as large
130 * as |bytes_to_read|. May perform a partial read. Returns the number of bytes
131 * read or an error code. If the return value is 0, then it indicates that
132 * end-of-file was reached.
133 * This method won't return more than 1 megabyte, so if |bytes_to_read|
134 * exceeds 1 megabyte, it will always perform a partial read.
135 * Multiple outstanding read requests are not supported.
137 int32_t (*Read)(PP_Resource tcp_socket,
138 char* buffer,
139 int32_t bytes_to_read,
140 struct PP_CompletionCallback callback);
142 * Writes data to the socket. May perform a partial write. Returns the number
143 * of bytes written or an error code.
144 * This method won't write more than 1 megabyte, so if |bytes_to_write|
145 * exceeds 1 megabyte, it will always perform a partial write.
146 * Multiple outstanding write requests are not supported.
148 int32_t (*Write)(PP_Resource tcp_socket,
149 const char* buffer,
150 int32_t bytes_to_write,
151 struct PP_CompletionCallback callback);
153 * Cancels any IO that may be pending, and disconnects the socket. Any pending
154 * callbacks will still run, reporting PP_Error_Aborted if pending IO was
155 * interrupted. It is NOT valid to call Connect() again after a call to this
156 * method. Note: If the socket is destroyed when it is still connected, then
157 * it will be implicitly disconnected, so you are not required to call this
158 * method.
160 void (*Disconnect)(PP_Resource tcp_socket);
162 * Sets an option on |tcp_socket|. Supported |name| and |value| parameters
163 * are as described for PP_TCPSocketOption_Private. |callback| will be
164 * invoked with PP_OK if setting the option succeeds, or an error code
165 * otherwise. The socket must be connection before SetOption is called.
167 int32_t (*SetOption)(PP_Resource tcp_socket,
168 PP_TCPSocketOption_Private name,
169 struct PP_Var value,
170 struct PP_CompletionCallback callback);
173 typedef struct PPB_TCPSocket_Private_0_5 PPB_TCPSocket_Private;
175 struct PPB_TCPSocket_Private_0_3 {
176 PP_Resource (*Create)(PP_Instance instance);
177 PP_Bool (*IsTCPSocket)(PP_Resource resource);
178 int32_t (*Connect)(PP_Resource tcp_socket,
179 const char* host,
180 uint16_t port,
181 struct PP_CompletionCallback callback);
182 int32_t (*ConnectWithNetAddress)(PP_Resource tcp_socket,
183 const struct PP_NetAddress_Private* addr,
184 struct PP_CompletionCallback callback);
185 PP_Bool (*GetLocalAddress)(PP_Resource tcp_socket,
186 struct PP_NetAddress_Private* local_addr);
187 PP_Bool (*GetRemoteAddress)(PP_Resource tcp_socket,
188 struct PP_NetAddress_Private* remote_addr);
189 int32_t (*SSLHandshake)(PP_Resource tcp_socket,
190 const char* server_name,
191 uint16_t server_port,
192 struct PP_CompletionCallback callback);
193 int32_t (*Read)(PP_Resource tcp_socket,
194 char* buffer,
195 int32_t bytes_to_read,
196 struct PP_CompletionCallback callback);
197 int32_t (*Write)(PP_Resource tcp_socket,
198 const char* buffer,
199 int32_t bytes_to_write,
200 struct PP_CompletionCallback callback);
201 void (*Disconnect)(PP_Resource tcp_socket);
204 struct PPB_TCPSocket_Private_0_4 {
205 PP_Resource (*Create)(PP_Instance instance);
206 PP_Bool (*IsTCPSocket)(PP_Resource resource);
207 int32_t (*Connect)(PP_Resource tcp_socket,
208 const char* host,
209 uint16_t port,
210 struct PP_CompletionCallback callback);
211 int32_t (*ConnectWithNetAddress)(PP_Resource tcp_socket,
212 const struct PP_NetAddress_Private* addr,
213 struct PP_CompletionCallback callback);
214 PP_Bool (*GetLocalAddress)(PP_Resource tcp_socket,
215 struct PP_NetAddress_Private* local_addr);
216 PP_Bool (*GetRemoteAddress)(PP_Resource tcp_socket,
217 struct PP_NetAddress_Private* remote_addr);
218 int32_t (*SSLHandshake)(PP_Resource tcp_socket,
219 const char* server_name,
220 uint16_t server_port,
221 struct PP_CompletionCallback callback);
222 PP_Resource (*GetServerCertificate)(PP_Resource tcp_socket);
223 PP_Bool (*AddChainBuildingCertificate)(PP_Resource tcp_socket,
224 PP_Resource certificate,
225 PP_Bool is_trusted);
226 int32_t (*Read)(PP_Resource tcp_socket,
227 char* buffer,
228 int32_t bytes_to_read,
229 struct PP_CompletionCallback callback);
230 int32_t (*Write)(PP_Resource tcp_socket,
231 const char* buffer,
232 int32_t bytes_to_write,
233 struct PP_CompletionCallback callback);
234 void (*Disconnect)(PP_Resource tcp_socket);
237 * @}
240 #endif /* PPAPI_C_PRIVATE_PPB_TCP_SOCKET_PRIVATE_H_ */