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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_udp_socket.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 "content/browser/renderer_host/pepper/pepper_udp_socket.h" 5 #include "content/browser/renderer_host/pepper/pepper_udp_socket.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" 11 #include "content/browser/renderer_host/pepper/pepper_message_filter.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/udp/udp_server_socket.h" 15 #include "net/udp/udp_server_socket.h"
16 #include "ppapi/proxy/ppapi_messages.h" 16 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/private/net_address_private_impl.h" 17 #include "ppapi/shared_impl/private/net_address_private_impl.h"
18 18
19 using content::BrowserThread; 19 using content::BrowserThread;
20 using ppapi::NetAddressPrivateImpl; 20 using ppapi::NetAddressPrivateImpl;
21 21
22 PepperUDPSocket::PepperUDPSocket( 22 PepperUDPSocket::PepperUDPSocket(
23 PepperMessageFilter* manager, 23 PepperMessageFilter* manager,
24 int32 routing_id, 24 int32 routing_id,
25 uint32 plugin_dispatcher_id, 25 uint32 plugin_dispatcher_id,
26 uint32 socket_id) 26 uint32 socket_id)
27 : manager_(manager), 27 : manager_(manager),
28 routing_id_(routing_id), 28 routing_id_(routing_id),
29 plugin_dispatcher_id_(plugin_dispatcher_id), 29 plugin_dispatcher_id_(plugin_dispatcher_id),
30 socket_id_(socket_id) { 30 socket_id_(socket_id),
31 allow_address_reuse_(false),
32 allow_broadcast_(false) {
31 DCHECK(manager); 33 DCHECK(manager);
32 } 34 }
33 35
34 PepperUDPSocket::~PepperUDPSocket() { 36 PepperUDPSocket::~PepperUDPSocket() {
35 // Make sure there are no further callbacks from socket_. 37 // Make sure there are no further callbacks from socket_.
36 if (socket_.get()) 38 if (socket_.get())
37 socket_->Close(); 39 socket_->Close();
38 } 40 }
39 41
42 void PepperUDPSocket::AllowAddressReuse(bool value) {
43 allow_address_reuse_ = value;
44 }
45
46 void PepperUDPSocket::AllowBroadcast(bool value) {
47 allow_broadcast_ = value;
48 }
49
40 void PepperUDPSocket::Bind(const PP_NetAddress_Private& addr) { 50 void PepperUDPSocket::Bind(const PP_NetAddress_Private& addr) {
41 socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source())); 51 socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source()));
42 52
43 net::IPEndPoint address; 53 net::IPEndPoint address;
44 if (!socket_.get() || 54 if (!socket_.get() ||
45 !NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address)) { 55 !NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address)) {
46 SendBindACKError(); 56 SendBindACKError();
47 return; 57 return;
48 } 58 }
49 59
60 if (allow_address_reuse_)
61 socket_->AllowAddressReuse();
62 if (allow_broadcast_)
63 socket_->AllowBroadcast();
64
50 int result = socket_->Listen(address); 65 int result = socket_->Listen(address);
51 66
52 if (result == net::OK && 67 if (result == net::OK &&
53 socket_->GetLocalAddress(&bound_address_) != net::OK) { 68 socket_->GetLocalAddress(&bound_address_) != net::OK) {
54 SendBindACKError(); 69 SendBindACKError();
55 return; 70 return;
56 } 71 }
57 72
58 OnBindCompleted(result); 73 OnBindCompleted(result);
59 } 74 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 168
154 if (result < 0) { 169 if (result < 0) {
155 SendSendToACKError(); 170 SendSendToACKError();
156 } else { 171 } else {
157 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK( 172 manager_->Send(new PpapiMsg_PPBUDPSocket_SendToACK(
158 routing_id_, plugin_dispatcher_id_, socket_id_, true, result)); 173 routing_id_, plugin_dispatcher_id_, socket_id_, true, result));
159 } 174 }
160 175
161 sendto_buffer_ = NULL; 176 sendto_buffer_ = NULL;
162 } 177 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_udp_socket.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698