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

Side by Side Diff: ppapi/shared_impl/private/udp_socket_private_impl.cc

Issue 10735056: AllowBroadcast() is exposed to NaCl. (Closed) Base URL: http://git.chromium.org/chromium/src.git@udp_broadcast
Patch Set: Sync. Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/shared_impl/private/udp_socket_private_impl.h" 5 #include "ppapi/shared_impl/private/udp_socket_private_impl.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "ppapi/c/pp_bool.h"
15 #include "ppapi/c/pp_completion_callback.h" 16 #include "ppapi/c/pp_completion_callback.h"
16 #include "ppapi/c/pp_errors.h" 17 #include "ppapi/c/pp_errors.h"
17 18
18 namespace ppapi { 19 namespace ppapi {
19 20
20 const int32_t UDPSocketPrivateImpl::kMaxReadSize = 1024 * 1024; 21 const int32_t UDPSocketPrivateImpl::kMaxReadSize = 1024 * 1024;
21 const int32_t UDPSocketPrivateImpl::kMaxWriteSize = 1024 * 1024; 22 const int32_t UDPSocketPrivateImpl::kMaxWriteSize = 1024 * 1024;
22 23
23 UDPSocketPrivateImpl::UDPSocketPrivateImpl(const HostResource& resource, 24 UDPSocketPrivateImpl::UDPSocketPrivateImpl(const HostResource& resource,
24 uint32 socket_id) 25 uint32 socket_id)
25 : Resource(OBJECT_IS_PROXY, resource) { 26 : Resource(OBJECT_IS_PROXY, resource) {
26 Init(socket_id); 27 Init(socket_id);
27 } 28 }
28 29
29 UDPSocketPrivateImpl::UDPSocketPrivateImpl(PP_Instance instance, 30 UDPSocketPrivateImpl::UDPSocketPrivateImpl(PP_Instance instance,
30 uint32 socket_id) 31 uint32 socket_id)
31 : Resource(OBJECT_IS_IMPL, instance) { 32 : Resource(OBJECT_IS_IMPL, instance) {
32 Init(socket_id); 33 Init(socket_id);
33 } 34 }
34 35
35 UDPSocketPrivateImpl::~UDPSocketPrivateImpl() { 36 UDPSocketPrivateImpl::~UDPSocketPrivateImpl() {
36 } 37 }
37 38
38 thunk::PPB_UDPSocket_Private_API* 39 thunk::PPB_UDPSocket_Private_API*
39 UDPSocketPrivateImpl::AsPPB_UDPSocket_Private_API() { 40 UDPSocketPrivateImpl::AsPPB_UDPSocket_Private_API() {
40 return this; 41 return this;
41 } 42 }
42 43
44 int32_t UDPSocketPrivateImpl::SetSocketFeature(PP_UDPSocketFeature_Private name,
45 PP_Var value) {
46 if (bound_ || closed_)
47 return PP_ERROR_FAILED;
48
49 switch (name) {
50 case PP_UDPSOCKETFEATURE_ADDRESS_REUSE:
51 case PP_UDPSOCKETFEATURE_BROADCAST:
52 if (PP_VARTYPE_BOOL != value.type)
viettrungluu 2012/08/27 18:33:54 I think we'd generally prefer |value.type != PP_VA
ygorshenin1 2012/08/27 19:12:47 Done.
53 return PP_ERROR_BADARGUMENT;
54 SendBoolSocketFeature(static_cast<int32_t>(name),
55 PP_ToBool(value.value.as_bool));
56 break;
57 default:
58 return PP_ERROR_BADARGUMENT;
59 }
60 return PP_OK;
61 }
62
43 int32_t UDPSocketPrivateImpl::Bind(const PP_NetAddress_Private* addr, 63 int32_t UDPSocketPrivateImpl::Bind(const PP_NetAddress_Private* addr,
44 scoped_refptr<TrackedCallback> callback) { 64 scoped_refptr<TrackedCallback> callback) {
45 if (!addr) 65 if (!addr)
46 return PP_ERROR_BADARGUMENT; 66 return PP_ERROR_BADARGUMENT;
47 if (bound_ || closed_) 67 if (bound_ || closed_)
48 return PP_ERROR_FAILED; 68 return PP_ERROR_FAILED;
49 if (TrackedCallback::IsPending(bind_callback_)) 69 if (TrackedCallback::IsPending(bind_callback_))
50 return PP_ERROR_INPROGRESS; 70 return PP_ERROR_INPROGRESS;
51 71
52 bind_callback_ = callback; 72 bind_callback_ = callback;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 arraysize(bound_addr_.data) * sizeof(*bound_addr_.data)); 216 arraysize(bound_addr_.data) * sizeof(*bound_addr_.data));
197 } 217 }
198 218
199 void UDPSocketPrivateImpl::PostAbortIfNecessary( 219 void UDPSocketPrivateImpl::PostAbortIfNecessary(
200 scoped_refptr<TrackedCallback>* callback) { 220 scoped_refptr<TrackedCallback>* callback) {
201 if (callback->get()) 221 if (callback->get())
202 (*callback)->PostAbort(); 222 (*callback)->PostAbort();
203 } 223 }
204 224
205 } // namespace ppapi 225 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698