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.
5 // From ppb_tcp_socket.idl modified Thu Jun 20 16:36:53 2013.
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_tcp_socket.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppb_instance_api.h"
13 #include "ppapi/thunk/ppb_tcp_socket_api.h"
14 #include "ppapi/thunk/resource_creation_api.h"
15 #include "ppapi/thunk/thunk.h"
22 PP_Resource
Create(PP_Instance instance
) {
23 VLOG(4) << "PPB_TCPSocket::Create()";
24 EnterResourceCreation
enter(instance
);
27 return enter
.functions()->CreateTCPSocket(instance
);
30 PP_Bool
IsTCPSocket(PP_Resource resource
) {
31 VLOG(4) << "PPB_TCPSocket::IsTCPSocket()";
32 EnterResource
<PPB_TCPSocket_API
> enter(resource
, false);
33 return PP_FromBool(enter
.succeeded());
36 int32_t Connect(PP_Resource tcp_socket
,
38 struct PP_CompletionCallback callback
) {
39 VLOG(4) << "PPB_TCPSocket::Connect()";
40 EnterResource
<PPB_TCPSocket_API
> enter(tcp_socket
, callback
, true);
42 return enter
.retval();
43 return enter
.SetResult(enter
.object()->Connect(addr
, enter
.callback()));
46 PP_Resource
GetLocalAddress(PP_Resource tcp_socket
) {
47 VLOG(4) << "PPB_TCPSocket::GetLocalAddress()";
48 EnterResource
<PPB_TCPSocket_API
> enter(tcp_socket
, true);
51 return enter
.object()->GetLocalAddress();
54 PP_Resource
GetRemoteAddress(PP_Resource tcp_socket
) {
55 VLOG(4) << "PPB_TCPSocket::GetRemoteAddress()";
56 EnterResource
<PPB_TCPSocket_API
> enter(tcp_socket
, true);
59 return enter
.object()->GetRemoteAddress();
62 int32_t Read(PP_Resource tcp_socket
,
64 int32_t bytes_to_read
,
65 struct PP_CompletionCallback callback
) {
66 VLOG(4) << "PPB_TCPSocket::Read()";
67 EnterResource
<PPB_TCPSocket_API
> enter(tcp_socket
, callback
, true);
69 return enter
.retval();
70 return enter
.SetResult(enter
.object()->Read(buffer
,
75 int32_t Write(PP_Resource tcp_socket
,
77 int32_t bytes_to_write
,
78 struct PP_CompletionCallback callback
) {
79 VLOG(4) << "PPB_TCPSocket::Write()";
80 EnterResource
<PPB_TCPSocket_API
> enter(tcp_socket
, callback
, true);
82 return enter
.retval();
83 return enter
.SetResult(enter
.object()->Write(buffer
,
88 void Close(PP_Resource tcp_socket
) {
89 VLOG(4) << "PPB_TCPSocket::Close()";
90 EnterResource
<PPB_TCPSocket_API
> enter(tcp_socket
, true);
93 enter
.object()->Close();
96 int32_t SetOption(PP_Resource tcp_socket
,
97 PP_TCPSocket_Option name
,
99 struct PP_CompletionCallback callback
) {
100 VLOG(4) << "PPB_TCPSocket::SetOption()";
101 EnterResource
<PPB_TCPSocket_API
> enter(tcp_socket
, callback
, true);
103 return enter
.retval();
104 return enter
.SetResult(enter
.object()->SetOption(name
,
109 const PPB_TCPSocket_1_0 g_ppb_tcpsocket_thunk_1_0
= {
123 const PPB_TCPSocket_1_0
* GetPPB_TCPSocket_1_0_Thunk() {
124 return &g_ppb_tcpsocket_thunk_1_0
;