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

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 "ppapi/proxy/ppapi_messages.h" 7 #include "ppapi/proxy/ppapi_messages.h"
8 #include "ppapi/shared_impl/ppb_tcp_socket_shared.h"
8 #include "ppapi/thunk/enter.h" 9 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_net_address_api.h" 10 #include "ppapi/thunk/ppb_net_address_api.h"
10 11
11 namespace ppapi { 12 namespace ppapi {
12 namespace proxy { 13 namespace proxy {
13 14
14 namespace { 15 namespace {
15 16
16 typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API> 17 typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API>
17 EnterNetAddressNoLock; 18 EnterNetAddressNoLock;
18 19
19 } // namespace 20 } // namespace
20 21
21 TCPSocketResource::TCPSocketResource(Connection connection, 22 TCPSocketResource::TCPSocketResource(Connection connection,
22 PP_Instance instance) 23 PP_Instance instance)
23 : TCPSocketResourceBase(connection, instance, false) { 24 : TCPSocketResourceBase(connection, instance, TCP_SOCKET_VERSION_1_0) {
24 SendCreate(BROWSER, PpapiHostMsg_TCPSocket_Create()); 25 SendCreate(BROWSER,
26 PpapiHostMsg_TCPSocket_Create(
27 TCP_SOCKET_VERSION_1_0, PP_NETADDRESS_FAMILY_UNSPECIFIED));
28 }
29
30 TCPSocketResource::TCPSocketResource(Connection connection,
31 PP_Instance instance,
32 PP_NetAddress_Family family)
33 : TCPSocketResourceBase(connection, instance,
34 TCP_SOCKET_VERSION_1_1_OR_ABOVE) {
35 SendCreate(BROWSER,
36 PpapiHostMsg_TCPSocket_Create(
37 TCP_SOCKET_VERSION_1_1_OR_ABOVE, family));
38 }
39
40 TCPSocketResource::TCPSocketResource(Connection connection,
41 PP_Instance instance,
42 int pending_host_id,
43 const PP_NetAddress_Private& local_addr,
44 const PP_NetAddress_Private& remote_addr)
45 : TCPSocketResourceBase(connection, instance,
46 TCP_SOCKET_VERSION_1_1_OR_ABOVE, local_addr,
47 remote_addr) {
48 AttachToPendingHost(BROWSER, pending_host_id);
25 } 49 }
26 50
27 TCPSocketResource::~TCPSocketResource() { 51 TCPSocketResource::~TCPSocketResource() {
28 DisconnectImpl(); 52 CloseImpl();
29 } 53 }
30 54
31 thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() { 55 thunk::PPB_TCPSocket_API* TCPSocketResource::AsPPB_TCPSocket_API() {
32 return this; 56 return this;
33 } 57 }
34 58
59 int32_t TCPSocketResource::Bind(PP_Resource addr,
60 scoped_refptr<TrackedCallback> callback) {
61 EnterNetAddressNoLock enter(addr, true);
62 if (enter.failed())
63 return PP_ERROR_BADARGUMENT;
64
65 return BindImpl(&enter.object()->GetNetAddressPrivate(), callback);
66 }
67
35 int32_t TCPSocketResource::Connect(PP_Resource addr, 68 int32_t TCPSocketResource::Connect(PP_Resource addr,
36 scoped_refptr<TrackedCallback> callback) { 69 scoped_refptr<TrackedCallback> callback) {
37 EnterNetAddressNoLock enter(addr, true); 70 EnterNetAddressNoLock enter(addr, true);
38 if (enter.failed()) 71 if (enter.failed())
39 return PP_ERROR_BADARGUMENT; 72 return PP_ERROR_BADARGUMENT;
40 73
41 return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(), 74 return ConnectWithNetAddressImpl(&enter.object()->GetNetAddressPrivate(),
42 callback); 75 callback);
43 } 76 }
44 77
(...skipping 26 matching lines...) Expand all
71 scoped_refptr<TrackedCallback> callback) { 104 scoped_refptr<TrackedCallback> callback) {
72 return ReadImpl(buffer, bytes_to_read, callback); 105 return ReadImpl(buffer, bytes_to_read, callback);
73 } 106 }
74 107
75 int32_t TCPSocketResource::Write(const char* buffer, 108 int32_t TCPSocketResource::Write(const char* buffer,
76 int32_t bytes_to_write, 109 int32_t bytes_to_write,
77 scoped_refptr<TrackedCallback> callback) { 110 scoped_refptr<TrackedCallback> callback) {
78 return WriteImpl(buffer, bytes_to_write, callback); 111 return WriteImpl(buffer, bytes_to_write, callback);
79 } 112 }
80 113
114 int32_t TCPSocketResource::Listen(int32_t backlog,
115 scoped_refptr<TrackedCallback> callback) {
116 return ListenImpl(backlog, callback);
117 }
118
119 int32_t TCPSocketResource::Accept(PP_Resource* accepted_tcp_socket,
120 scoped_refptr<TrackedCallback> callback) {
121 return AcceptImpl(accepted_tcp_socket, callback);
122 }
123
81 void TCPSocketResource::Close() { 124 void TCPSocketResource::Close() {
82 DisconnectImpl(); 125 CloseImpl();
83 } 126 }
84 127
85 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name, 128 int32_t TCPSocketResource::SetOption(PP_TCPSocket_Option name,
86 const PP_Var& value, 129 const PP_Var& value,
87 scoped_refptr<TrackedCallback> callback) { 130 scoped_refptr<TrackedCallback> callback) {
88 return SetOptionImpl(name, value, callback); 131 return SetOptionImpl(name, value, callback);
89 } 132 }
90 133
134 PP_Resource TCPSocketResource::CreateAcceptedSocket(
135 int pending_host_id,
136 const PP_NetAddress_Private& local_addr,
137 const PP_NetAddress_Private& remote_addr) {
138 return (new TCPSocketResource(connection(), pp_instance(), pending_host_id,
139 local_addr, remote_addr))->GetReference();
140 }
141
91 } // namespace proxy 142 } // namespace proxy
92 } // namespace ppapi 143 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698