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.
5 #include "ppapi/c/pp_completion_callback.h"
6 #include "ppapi/c/pp_errors.h"
7 #include "ppapi/c/private/ppb_tcp_socket_private.h"
8 #include "ppapi/shared_impl/tracked_callback.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/thunk.h"
11 #include "ppapi/thunk/ppb_tcp_socket_private_api.h"
12 #include "ppapi/thunk/resource_creation_api.h"
19 typedef EnterResource
<PPB_TCPSocket_Private_API
> EnterTCP
;
21 PP_Resource
Create(PP_Instance instance
) {
22 EnterResourceCreation
enter(instance
);
25 return enter
.functions()->CreateTCPSocketPrivate(instance
);
28 PP_Bool
IsTCPSocket(PP_Resource resource
) {
29 EnterTCP
enter(resource
, false);
30 return PP_FromBool(enter
.succeeded());
33 int32_t Connect(PP_Resource tcp_socket
,
36 PP_CompletionCallback callback
) {
37 EnterTCP
enter(tcp_socket
, callback
, true);
39 return enter
.retval();
40 return enter
.SetResult(enter
.object()->Connect(host
, port
, enter
.callback()));
43 int32_t ConnectWithNetAddress(PP_Resource tcp_socket
,
44 const PP_NetAddress_Private
* addr
,
45 PP_CompletionCallback callback
) {
46 EnterTCP
enter(tcp_socket
, callback
, true);
48 return enter
.retval();
49 return enter
.SetResult(
50 enter
.object()->ConnectWithNetAddress(addr
, enter
.callback()));
53 PP_Bool
GetLocalAddress(PP_Resource tcp_socket
,
54 PP_NetAddress_Private
* local_addr
) {
55 EnterTCP
enter(tcp_socket
, true);
58 return enter
.object()->GetLocalAddress(local_addr
);
61 PP_Bool
GetRemoteAddress(PP_Resource tcp_socket
,
62 PP_NetAddress_Private
* remote_addr
) {
63 EnterTCP
enter(tcp_socket
, true);
66 return enter
.object()->GetRemoteAddress(remote_addr
);
69 int32_t SSLHandshake(PP_Resource tcp_socket
,
70 const char* server_name
,
72 PP_CompletionCallback callback
) {
73 EnterTCP
enter(tcp_socket
, callback
, true);
75 return enter
.retval();
76 return enter
.SetResult(enter
.object()->SSLHandshake(server_name
, server_port
,
80 PP_Resource
GetServerCertificate(PP_Resource tcp_socket
) {
81 EnterTCP
enter(tcp_socket
, true);
84 return enter
.object()->GetServerCertificate();
87 PP_Bool
AddChainBuildingCertificate(PP_Resource tcp_socket
,
88 PP_Resource certificate
,
90 EnterTCP
enter(tcp_socket
, true);
93 return enter
.object()->AddChainBuildingCertificate(certificate
, trusted
);
96 int32_t Read(PP_Resource tcp_socket
,
98 int32_t bytes_to_read
,
99 PP_CompletionCallback callback
) {
100 EnterTCP
enter(tcp_socket
, callback
, true);
102 return enter
.retval();
103 return enter
.SetResult(enter
.object()->Read(buffer
, bytes_to_read
,
107 int32_t Write(PP_Resource tcp_socket
,
109 int32_t bytes_to_write
,
110 PP_CompletionCallback callback
) {
111 EnterTCP
enter(tcp_socket
, callback
, true);
113 return enter
.retval();
114 return enter
.SetResult(enter
.object()->Write(buffer
, bytes_to_write
,
118 void Disconnect(PP_Resource tcp_socket
) {
119 EnterTCP
enter(tcp_socket
, true);
120 if (enter
.succeeded())
121 enter
.object()->Disconnect();
124 int32_t SetOption(PP_Resource tcp_socket
,
125 PP_TCPSocketOption_Private name
,
127 PP_CompletionCallback callback
) {
128 EnterTCP
enter(tcp_socket
, callback
, true);
130 return enter
.retval();
131 return enter
.SetResult(
132 enter
.object()->SetOption(name
, value
, enter
.callback()));
135 const PPB_TCPSocket_Private_0_3 g_ppb_tcp_socket_thunk_0_3
= {
139 &ConnectWithNetAddress
,
148 const PPB_TCPSocket_Private_0_4 g_ppb_tcp_socket_thunk_0_4
= {
152 &ConnectWithNetAddress
,
156 &GetServerCertificate
,
157 &AddChainBuildingCertificate
,
163 const PPB_TCPSocket_Private_0_5 g_ppb_tcp_socket_thunk_0_5
= {
167 &ConnectWithNetAddress
,
171 &GetServerCertificate
,
172 &AddChainBuildingCertificate
,
181 const PPB_TCPSocket_Private_0_3
* GetPPB_TCPSocket_Private_0_3_Thunk() {
182 return &g_ppb_tcp_socket_thunk_0_3
;
185 const PPB_TCPSocket_Private_0_4
* GetPPB_TCPSocket_Private_0_4_Thunk() {
186 return &g_ppb_tcp_socket_thunk_0_4
;
189 const PPB_TCPSocket_Private_0_5
* GetPPB_TCPSocket_Private_0_5_Thunk() {
190 return &g_ppb_tcp_socket_thunk_0_5
;