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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_udp.cc

Issue 2867693004: Snapshot of all changes to get jumbo in blink and content.
Patch Set: Exclude certain files from jumbo because of a Windows problem Created 3 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/p2p/socket_host_udp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" 16 #include "content/browser/renderer_host/p2p/socket_host_throttler.h"
17 #include "content/common/p2p_messages.h" 17 #include "content/common/p2p_messages.h"
18 #include "content/public/browser/content_browser_client.h" 18 #include "content/public/browser/content_browser_client.h"
19 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
20 #include "ipc/ipc_sender.h" 20 #include "ipc/ipc_sender.h"
21 #include "net/base/io_buffer.h" 21 #include "net/base/io_buffer.h"
22 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/log/net_log_source.h" 23 #include "net/log/net_log_source.h"
24 #include "third_party/webrtc/media/base/rtputils.h" 24 #include "third_party/webrtc/media/base/rtputils.h"
25 25
26 namespace { 26 namespace {
27 27
28 // UDP packets cannot be bigger than 64k. 28 // UDP packets cannot be bigger than 64k.
29 const int kReadBufferSize = 65536; 29 const int kUDPReadBufferSize = 65536;
30 // Socket receive buffer size. 30 // Socket receive buffer size.
31 const int kRecvSocketBufferSize = 65536; // 64K 31 const int kUDPRecvSocketBufferSize = 65536; // 64K
32 32
33 // Defines set of transient errors. These errors are ignored when we get them 33 // Defines set of transient errors. These errors are ignored when we get them
34 // from sendto() or recvfrom() calls. 34 // from sendto() or recvfrom() calls.
35 // 35 //
36 // net::ERR_OUT_OF_MEMORY 36 // net::ERR_OUT_OF_MEMORY
37 // 37 //
38 // This is caused by ENOBUFS which means the buffer of the network interface 38 // This is caused by ENOBUFS which means the buffer of the network interface
39 // is full. 39 // is full.
40 // 40 //
41 // net::ERR_CONNECTION_RESET 41 // net::ERR_CONNECTION_RESET
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 << (min_port == 0 164 << (min_port == 0
165 ? base::StringPrintf(":%d", local_address.port()) 165 ? base::StringPrintf(":%d", local_address.port())
166 : base::StringPrintf(", port range [%d-%d]", min_port, 166 : base::StringPrintf(", port range [%d-%d]", min_port,
167 max_port)) 167 max_port))
168 << " failed: " << result; 168 << " failed: " << result;
169 OnError(); 169 OnError();
170 return false; 170 return false;
171 } 171 }
172 172
173 // Setting recv socket buffer size. 173 // Setting recv socket buffer size.
174 if (socket_->SetReceiveBufferSize(kRecvSocketBufferSize) != net::OK) { 174 if (socket_->SetReceiveBufferSize(kUDPRecvSocketBufferSize) != net::OK) {
175 LOG(WARNING) << "Failed to set socket receive buffer size to " 175 LOG(WARNING) << "Failed to set socket receive buffer size to "
176 << kRecvSocketBufferSize; 176 << kUDPRecvSocketBufferSize;
177 } 177 }
178 178
179 net::IPEndPoint address; 179 net::IPEndPoint address;
180 result = socket_->GetLocalAddress(&address); 180 result = socket_->GetLocalAddress(&address);
181 if (result < 0) { 181 if (result < 0) {
182 LOG(ERROR) << "P2PSocketHostUdp::Init(): unable to get local address: " 182 LOG(ERROR) << "P2PSocketHostUdp::Init(): unable to get local address: "
183 << result; 183 << result;
184 OnError(); 184 OnError();
185 return false; 185 return false;
186 } 186 }
187 VLOG(1) << "Local address: " << address.ToString(); 187 VLOG(1) << "Local address: " << address.ToString();
188 188
189 state_ = STATE_OPEN; 189 state_ = STATE_OPEN;
190 190
191 SetSendBufferSize(); 191 SetSendBufferSize();
192 192
193 // NOTE: Remote address will be same as what renderer provided. 193 // NOTE: Remote address will be same as what renderer provided.
194 message_sender_->Send(new P2PMsg_OnSocketCreated( 194 message_sender_->Send(new P2PMsg_OnSocketCreated(
195 id_, address, remote_address.ip_address)); 195 id_, address, remote_address.ip_address));
196 196
197 recv_buffer_ = new net::IOBuffer(kReadBufferSize); 197 recv_buffer_ = new net::IOBuffer(kUDPReadBufferSize);
198 DoRead(); 198 DoRead();
199 199
200 return true; 200 return true;
201 } 201 }
202 202
203 void P2PSocketHostUdp::OnError() { 203 void P2PSocketHostUdp::OnError() {
204 socket_.reset(); 204 socket_.reset();
205 send_queue_.clear(); 205 send_queue_.clear();
206 206
207 if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN) 207 if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN)
208 message_sender_->Send(new P2PMsg_OnError(id_)); 208 message_sender_->Send(new P2PMsg_OnError(id_));
209 209
210 state_ = STATE_ERROR; 210 state_ = STATE_ERROR;
211 } 211 }
212 212
213 void P2PSocketHostUdp::DoRead() { 213 void P2PSocketHostUdp::DoRead() {
214 int result; 214 int result;
215 do { 215 do {
216 result = socket_->RecvFrom( 216 result = socket_->RecvFrom(
217 recv_buffer_.get(), 217 recv_buffer_.get(),
218 kReadBufferSize, 218 kUDPReadBufferSize,
219 &recv_address_, 219 &recv_address_,
220 base::Bind(&P2PSocketHostUdp::OnRecv, base::Unretained(this))); 220 base::Bind(&P2PSocketHostUdp::OnRecv, base::Unretained(this)));
221 if (result == net::ERR_IO_PENDING) 221 if (result == net::ERR_IO_PENDING)
222 return; 222 return;
223 HandleReadResult(result); 223 HandleReadResult(result);
224 } while (state_ == STATE_OPEN); 224 } while (state_ == STATE_OPEN);
225 } 225 }
226 226
227 void P2PSocketHostUdp::OnRecv(int result) { 227 void P2PSocketHostUdp::OnRecv(int result) {
228 HandleReadResult(result); 228 HandleReadResult(result);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 net::UDPServerSocket* socket = new net::UDPServerSocket( 452 net::UDPServerSocket* socket = new net::UDPServerSocket(
453 GetContentClient()->browser()->GetNetLog(), net::NetLogSource()); 453 GetContentClient()->browser()->GetNetLog(), net::NetLogSource());
454 #if defined(OS_WIN) 454 #if defined(OS_WIN)
455 socket->UseNonBlockingIO(); 455 socket->UseNonBlockingIO();
456 #endif 456 #endif
457 457
458 return base::WrapUnique(socket); 458 return base::WrapUnique(socket);
459 } 459 }
460 460
461 } // namespace content 461 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698