Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: ppapi/proxy/tcp_socket_resource.cc

Issue 24195004: PPB_TCPSocket: add support for TCP server socket operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/tcp_socket_resource.h ('k') | ppapi/proxy/tcp_socket_resource_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/tcp_socket_resource.h" 5 #include "ppapi/proxy/tcp_socket_resource.h"
6 6
7 #include "base/logging.h"
7 #include "ppapi/proxy/ppapi_messages.h" 8 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/shared_impl/ppb_tcp_socket_shared.h"
8 #include "ppapi/thunk/enter.h" 10 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_net_address_api.h" 11 #include "ppapi/thunk/ppb_net_address_api.h"
10 12
11 namespace ppapi { 13 namespace ppapi {
12 namespace proxy { 14 namespace proxy {
13 15
14 namespace { 16 namespace {
15 17
16 typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API> 18 typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API>
17 EnterNetAddressNoLock; 19 EnterNetAddressNoLock;
18 20
19 } // namespace 21 } // namespace
20 22
21 TCPSocketResource::TCPSocketResource(Connection connection, 23 TCPSocketResource::TCPSocketResource(Connection connection,
22 PP_Instance instance) 24 PP_Instance instance,
23 : TCPSocketResourceBase(connection, instance, false) { 25 TCPSocketVersion version)
24 SendCreate(BROWSER, PpapiHostMsg_TCPSocket_Create()); 26 : TCPSocketResourceBase(connection, instance, version) {
27 DCHECK_NE(version, TCP_SOCKET_VERSION_PRIVATE);
28 SendCreate(BROWSER, PpapiHostMsg_TCPSocket_Create(version));
29 }
30
31 TCPSocketResource::TCPSocketResource(Connection connection,
32 PP_Instance instance,
33 int pending_host_id,
34 const PP_NetAddress_Private& local_addr,
35 const PP_NetAddress_Private& remote_addr)
36 : TCPSocketResourceBase(connection, instance,
37 TCP_SOCKET_VERSION_1_1_OR_ABOVE, local_addr,
38 remote_addr) {
39 AttachToPendingHost(BROWSER, pending_host_id);
25 } 40 }
26 41
27 TCPSocketResource::~TCPSocketResource() { 42 TCPSocketResource::~TCPSocketResource() {
28 DisconnectImpl();
29 } 43 }
30 44
31 thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() { 45 thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() {
32 return this; 46 return this;
33 } 47 }
34 48
49 int32_t TCPSocketResource::Bind(PP_Resource addr,
50 scoped_refptr<TrackedCallback> callback) {
51 EnterNetAddressNoLock enter(addr, true);
52 if (enter.failed())
53 return PP_ERROR_BADARGUMENT;
54
55 return BindImpl(&enter.object()->GetNetAddressPrivate(), callback);
56 }
57
35 int32_t TCPSocketResource::Connect(PP_Resource addr, 58 int32_t TCPSocketResource::Connect(PP_Resource addr,
36 scoped_refptr<TrackedCallback> callback) { 59 scoped_refptr<TrackedCallback> callback) {
37 EnterNetAddressNoLock enter(addr, true); 60 EnterNetAddressNoLock enter(addr, true);
38 if (enter.failed()) 61 if (enter.failed())
39 return PP_ERROR_BADARGUMENT; 62 return PP_ERROR_BADARGUMENT;
40 63
41 return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(), 64 return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(),
42 callback); 65 callback);
43 } 66 }
44 67
(...skipping 26 matching lines...) Expand all
71 scoped_refptr<TrackedCallback> callback) { 94 scoped_refptr<TrackedCallback> callback) {
72 return ReadImpl(buffer, bytes_to_read, callback); 95 return ReadImpl(buffer, bytes_to_read, callback);
73 } 96 }
74 97
75 int32_t TCPSocketResource::Write(const char* buffer, 98 int32_t TCPSocketResource::Write(const char* buffer,
76 int32_t bytes_to_write, 99 int32_t bytes_to_write,
77 scoped_refptr<TrackedCallback> callback) { 100 scoped_refptr<TrackedCallback> callback) {
78 return WriteImpl(buffer, bytes_to_write, callback); 101 return WriteImpl(buffer, bytes_to_write, callback);
79 } 102 }
80 103
104 int32_t TCPSocketResource::Listen(int32_t backlog,
105 scoped_refptr<TrackedCallback> callback) {
106 return ListenImpl(backlog, callback);
107 }
108
109 int32_t TCPSocketResource::Accept(PP_Resource* accepted_tcp_socket,
110 scoped_refptr<TrackedCallback> callback) {
111 return AcceptImpl(accepted_tcp_socket, callback);
112 }
113
81 void TCPSocketResource::Close() { 114 void TCPSocketResource::Close() {
82 DisconnectImpl(); 115 CloseImpl();
83 } 116 }
84 117
85 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name, 118 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name,
86 const PP_Var& value, 119 const PP_Var& value,
87 scoped_refptr<TrackedCallback> callback) { 120 scoped_refptr<TrackedCallback> callback) {
88 return SetOptionImpl(name, value, callback); 121 return SetOptionImpl(name, value, callback);
89 } 122 }
90 123
124 PP_Resource TCPSocketResource::CreateAcceptedSocket(
125 int pending_host_id,
126 const PP_NetAddress_Private& local_addr,
127 const PP_NetAddress_Private& remote_addr) {
128 return (new TCPSocketResource(connection(), pp_instance(), pending_host_id,
129 local_addr, remote_addr))->GetReference();
130 }
131
91 } // namespace proxy 132 } // namespace proxy
92 } // namespace ppapi 133 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/tcp_socket_resource.h ('k') | ppapi/proxy/tcp_socket_resource_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698