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 #include "ppapi/proxy/tcp_socket_resource.h"
7 #include "ppapi/proxy/ppapi_messages.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_net_address_api.h"
16 typedef thunk::EnterResourceNoLock
<thunk::PPB_NetAddress_API
>
17 EnterNetAddressNoLock
;
21 TCPSocketResource::TCPSocketResource(Connection connection
,
23 : TCPSocketResourceBase(connection
, instance
, false) {
24 SendCreate(BROWSER
, PpapiHostMsg_TCPSocket_Create());
27 TCPSocketResource::~TCPSocketResource() {
31 thunk::PPB_TCPSocket_API
* TCPSocketResource::AsPPB_TCPSocket_API() {
35 int32_t TCPSocketResource::Connect(PP_Resource addr
,
36 scoped_refptr
<TrackedCallback
> callback
) {
37 EnterNetAddressNoLock
enter(addr
, true);
39 return PP_ERROR_BADARGUMENT
;
41 return ConnectWithNetAddressImpl(&enter
.object()->GetNetAddressPrivate(),
45 PP_Resource
TCPSocketResource::GetLocalAddress() {
46 PP_NetAddress_Private addr_private
;
47 if (!GetLocalAddressImpl(&addr_private
))
50 thunk::EnterResourceCreationNoLock
enter(pp_instance());
53 return enter
.functions()->CreateNetAddressFromNetAddressPrivate(
54 pp_instance(), addr_private
);
57 PP_Resource
TCPSocketResource::GetRemoteAddress() {
58 PP_NetAddress_Private addr_private
;
59 if (!GetRemoteAddressImpl(&addr_private
))
62 thunk::EnterResourceCreationNoLock
enter(pp_instance());
65 return enter
.functions()->CreateNetAddressFromNetAddressPrivate(
66 pp_instance(), addr_private
);
69 int32_t TCPSocketResource::Read(char* buffer
,
70 int32_t bytes_to_read
,
71 scoped_refptr
<TrackedCallback
> callback
) {
72 return ReadImpl(buffer
, bytes_to_read
, callback
);
75 int32_t TCPSocketResource::Write(const char* buffer
,
76 int32_t bytes_to_write
,
77 scoped_refptr
<TrackedCallback
> callback
) {
78 return WriteImpl(buffer
, bytes_to_write
, callback
);
81 void TCPSocketResource::Close() {
85 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name
,
87 scoped_refptr
<TrackedCallback
> callback
) {
88 return SetOptionImpl(name
, value
, callback
);