OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "ppapi/proxy/tcp_socket_resource.h" | |
6 | |
7 #include "ppapi/proxy/ppapi_messages.h" | |
8 #include "ppapi/thunk/enter.h" | |
9 #include "ppapi/thunk/ppb_net_address_api.h" | |
10 | |
11 namespace ppapi { | |
12 namespace proxy { | |
13 | |
14 namespace { | |
15 | |
16 typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API> | |
17 EnterNetAddressNoLock; | |
18 | |
19 } // namespace | |
20 | |
21 TCPSocketResource::TCPSocketResource(Connection connection, | |
22 PP_Instance instance) | |
23 : TCPSocketResourceBase(connection, instance, false) { | |
24 SendCreate(BROWSER, PpapiHostMsg_TCPSocket_CreatePrivate()); | |
yzshen1
2013/08/16 20:40:42
wrong message!
ygorshenin1
2013/08/19 14:33:35
Done.
| |
25 } | |
26 | |
27 TCPSocketResource::~TCPSocketResource() { | |
28 DisconnectImpl(); | |
29 } | |
30 | |
31 thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() { | |
32 return this; | |
33 } | |
34 | |
35 int32_t TCPSocketResource::Connect(PP_Resource addr, | |
36 scoped_refptr<TrackedCallback> callback) { | |
37 EnterNetAddressNoLock enter(addr, true); | |
38 if (enter.failed()) | |
39 return PP_ERROR_BADARGUMENT; | |
40 | |
41 return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(), | |
42 callback); | |
43 } | |
44 | |
45 PP_Resource TCPSocketResource::GetLocalAddress() { | |
46 PP_NetAddress_Private addr_private; | |
47 if (!GetLocalAddressImpl(&addr_private)) | |
48 return 0; | |
49 | |
50 thunk::EnterResourceCreationNoLock enter(pp_instance()); | |
51 if (enter.failed()) | |
52 return 0; | |
53 return enter.functions()->CreateNetAddressFromNetAddressPrivate( | |
54 pp_instance(), addr_private); | |
55 } | |
56 | |
57 PP_Resource TCPSocketResource::GetRemoteAddress() { | |
58 PP_NetAddress_Private addr_private; | |
59 if (!GetRemoteAddressImpl(&addr_private)) | |
60 return 0; | |
61 | |
62 thunk::EnterResourceCreationNoLock enter(pp_instance()); | |
63 if (enter.failed()) | |
64 return 0; | |
65 return enter.functions()->CreateNetAddressFromNetAddressPrivate( | |
66 pp_instance(), addr_private); | |
67 } | |
68 | |
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); | |
73 } | |
74 | |
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); | |
79 } | |
80 | |
81 void TCPSocketResource::Close() { | |
82 DisconnectImpl(); | |
83 } | |
84 | |
85 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name, | |
86 const PP_Var& value, | |
87 scoped_refptr<TrackedCallback> callback) { | |
88 return SetOptionImpl(name, value, callback); | |
89 } | |
90 | |
91 } // namespace proxy | |
92 } // namespace ppapi | |
OLD | NEW |