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.
6 /* From private/ppb_tcp_socket_private.idl modified Mon Jun 24 09:53:12 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
27 * This file defines the <code>PPB_TCPSocket_Private</code> interface.
36 /* Special value used for testing. Guaranteed to fail SetOption(). */
37 PP_TCPSOCKETOPTION_PRIVATE_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_PRIVATE_NO_DELAY
= 1
42 } PP_TCPSocketOption_Private
;
43 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocketOption_Private
, 4);
49 * @addtogroup Interfaces
53 * The <code>PPB_TCPSocket_Private</code> interface provides TCP socket
56 struct PPB_TCPSocket_Private_0_5
{
58 * Allocates a TCP socket resource.
60 PP_Resource (*Create
)(PP_Instance instance
);
62 * Determines if a given resource is TCP socket.
64 PP_Bool (*IsTCPSocket
)(PP_Resource resource
);
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
,
73 struct PP_CompletionCallback callback
);
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
);
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
);
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
);
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
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
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
125 PP_Bool (*AddChainBuildingCertificate
)(PP_Resource tcp_socket
,
126 PP_Resource certificate
,
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
,
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
,
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
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
,
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
,
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
,
195 int32_t bytes_to_read
,
196 struct PP_CompletionCallback callback
);
197 int32_t (*Write
)(PP_Resource tcp_socket
,
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
,
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
,
226 int32_t (*Read
)(PP_Resource tcp_socket
,
228 int32_t bytes_to_read
,
229 struct PP_CompletionCallback callback
);
230 int32_t (*Write
)(PP_Resource tcp_socket
,
232 int32_t bytes_to_write
,
233 struct PP_CompletionCallback callback
);
234 void (*Disconnect
)(PP_Resource tcp_socket
);
240 #endif /* PPAPI_C_PRIVATE_PPB_TCP_SOCKET_PRIVATE_H_ */