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

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
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(); 43 CloseImpl();
29 } 44 }
30 45
31 thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() { 46 thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() {
32 return this; 47 return this;
33 } 48 }
34 49
50 int32_t TCPSocketResource::Bind(PP_Resource addr,
51 scoped_refptr<TrackedCallback> callback) {
52 EnterNetAddressNoLock enter(addr, true);
53 if (enter.failed())
54 return PP_ERROR_BADARGUMENT;
55
56 return BindImpl(&enter.object()->GetNetAddressPrivate(), callback);
57 }
58
35 int32_t TCPSocketResource::Connect(PP_Resource addr, 59 int32_t TCPSocketResource::Connect(PP_Resource addr,
36 scoped_refptr<TrackedCallback> callback) { 60 scoped_refptr<TrackedCallback> callback) {
37 EnterNetAddressNoLock enter(addr, true); 61 EnterNetAddressNoLock enter(addr, true);
38 if (enter.failed()) 62 if (enter.failed())
39 return PP_ERROR_BADARGUMENT; 63 return PP_ERROR_BADARGUMENT;
40 64
41 return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(), 65 return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(),
42 callback); 66 callback);
43 } 67 }
44 68
(...skipping 26 matching lines...) Expand all
71 scoped_refptr<TrackedCallback> callback) { 95 scoped_refptr<TrackedCallback> callback) {
72 return ReadImpl(buffer, bytes_to_read, callback); 96 return ReadImpl(buffer, bytes_to_read, callback);
73 } 97 }
74 98
75 int32_t TCPSocketResource::Write(const char* buffer, 99 int32_t TCPSocketResource::Write(const char* buffer,
76 int32_t bytes_to_write, 100 int32_t bytes_to_write,
77 scoped_refptr<TrackedCallback> callback) { 101 scoped_refptr<TrackedCallback> callback) {
78 return WriteImpl(buffer, bytes_to_write, callback); 102 return WriteImpl(buffer, bytes_to_write, callback);
79 } 103 }
80 104
105 int32_t TCPSocketResource::Listen(int32_t backlog,
106 scoped_refptr<TrackedCallback> callback) {
107 return ListenImpl(backlog, callback);
108 }
109
110 int32_t TCPSocketResource::Accept(PP_Resource* accepted_tcp_socket,
111 scoped_refptr<TrackedCallback> callback) {
112 return AcceptImpl(accepted_tcp_socket, callback);
113 }
114
81 void TCPSocketResource::Close() { 115 void TCPSocketResource::Close() {
82 DisconnectImpl(); 116 CloseImpl();
83 } 117 }
84 118
85 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name, 119 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name,
86 const PP_Var& value, 120 const PP_Var& value,
87 scoped_refptr<TrackedCallback> callback) { 121 scoped_refptr<TrackedCallback> callback) {
88 return SetOptionImpl(name, value, callback); 122 return SetOptionImpl(name, value, callback);
89 } 123 }
90 124
125 PP_Resource TCPSocketResource::CreateAcceptedSocket(
126 int pending_host_id,
127 const PP_NetAddress_Private& local_addr,
128 const PP_NetAddress_Private& remote_addr) {
129 return (new TCPSocketResource(connection(), pp_instance(), pending_host_id,
130 local_addr, remote_addr))->GetReference();
131 }
132
91 } // namespace proxy 133 } // namespace proxy
92 } // namespace ppapi 134 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698