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

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

Issue 16282005: Introduce PPB_UDPSocket_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
(Empty)
1 // Copyright (c) 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/udp_socket_resource.h"
6
7 #include "ppapi/shared_impl/tracked_callback.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_net_address_api.h"
10 #include "ppapi/thunk/resource_creation_api.h"
11
12 namespace ppapi {
13 namespace proxy {
14
15 namespace {
16
17 typedef thunk::EnterResourceNoLock<thunk::PPB_NetAddress_API>
18 EnterNetAddressNoLock;
19
20 } // namespace
21
22 UDPSocketResource::UDPSocketResource(Connection connection,
23 PP_Instance instance)
24 : UDPSocketShared(connection, instance) {
25 }
26
27 UDPSocketResource::~UDPSocketResource() {
28 }
29
30 thunk::PPB_UDPSocket_API* UDPSocketResource::AsPPB_UDPSocket_API() {
31 return this;
32 }
33
34 int32_t UDPSocketResource::Bind(PP_Resource addr,
35 scoped_refptr<TrackedCallback> callback) {
36 EnterNetAddressNoLock enter(addr, true);
37 if (enter.failed())
38 return PP_ERROR_BADARGUMENT;
39
40 return BindImpl(&enter.object()->GetNetAddressPrivate(), callback);
41 }
42
43 PP_Resource UDPSocketResource::GetBoundAddress() {
44 PP_NetAddress_Private addr_private;
45 if (!GetBoundAddressImpl(&addr_private))
46 return 0;
47
48 thunk::EnterResourceCreationNoLock enter(pp_instance());
49 if (enter.failed())
50 return 0;
51 return enter.functions()->CreateNetAddressFromNetAddressPrivate(
52 pp_instance(), addr_private);
53 }
54
55 int32_t UDPSocketResource::RecvFrom(char* buffer,
56 int32_t num_bytes,
57 PP_Resource* addr,
58 scoped_refptr<TrackedCallback> callback) {
59 return RecvFromImpl(buffer, num_bytes, addr, callback);
60 }
61
62 int32_t UDPSocketResource::SendTo(const char* buffer,
63 int32_t num_bytes,
64 PP_Resource addr,
65 scoped_refptr<TrackedCallback> callback) {
66 EnterNetAddressNoLock enter(addr, true);
67 if (enter.failed())
68 return PP_ERROR_BADARGUMENT;
69
70 return SendToImpl(buffer, num_bytes, &enter.object()->GetNetAddressPrivate(),
71 callback);
72 }
73
74 void UDPSocketResource::Close() {
75 CloseImpl();
76 }
77
78 int32_t UDPSocketResource::SetOption(
79 PP_UDPSocket_Option_Dev name,
80 const PP_Var& value,
81 scoped_refptr<TrackedCallback> /* callback */) {
82 // TODO(yzshen): Add support for other options.
83 PP_UDPSocketFeature_Private feature;
84 switch (name) {
85 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE:
86 feature = PP_UDPSOCKETFEATURE_ADDRESS_REUSE;
87 break;
88 case PP_UDPSOCKET_OPTION_BROADCAST:
89 feature = PP_UDPSOCKETFEATURE_BROADCAST;
90 break;
91 default:
92 return PP_ERROR_NOTSUPPORTED;
93 }
94
95 return SetSocketFeatureImpl(feature, value);
96 }
97
98 } // namespace proxy
99 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698