OLD | NEW |
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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" |
11 #include "content/common/p2p_messages.h" | 11 #include "content/common/p2p_messages.h" |
12 #include "content/public/browser/content_browser_client.h" | 12 #include "content/public/browser/content_browser_client.h" |
13 #include "content/public/common/content_client.h" | 13 #include "content/public/common/content_client.h" |
14 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" | |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 // UDP packets cannot be bigger than 64k. | 21 // UDP packets cannot be bigger than 64k. |
23 const int kReadBufferSize = 65536; | 22 const int kReadBufferSize = 65536; |
24 // Socket receive buffer size. | 23 // Socket receive buffer size. |
25 const int kRecvSocketBufferSize = 65536; // 64K | 24 const int kRecvSocketBufferSize = 65536; // 64K |
26 | 25 |
27 // Defines set of transient errors. These errors are ignored when we get them | 26 // Defines set of transient errors. These errors are ignored when we get them |
28 // from sendto() or recvfrom() calls. | 27 // from sendto() or recvfrom() calls. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 int result = socket_->SetDiffServCodePoint(dscp); | 227 int result = socket_->SetDiffServCodePoint(dscp); |
229 if (result == net::OK) { | 228 if (result == net::OK) { |
230 last_dscp_ = dscp; | 229 last_dscp_ = dscp; |
231 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { | 230 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { |
232 // We receieved a non-transient error, and it seems we have | 231 // We receieved a non-transient error, and it seems we have |
233 // not changed the DSCP in the past, disable DSCP as it unlikely | 232 // not changed the DSCP in the past, disable DSCP as it unlikely |
234 // to work in the future. | 233 // to work in the future. |
235 last_dscp_ = net::DSCP_NO_CHANGE; | 234 last_dscp_ = net::DSCP_NO_CHANGE; |
236 } | 235 } |
237 } | 236 } |
238 packet_processing_helpers::ApplyPacketOptions( | |
239 packet.data->data(), packet.size, packet.packet_options, 0); | |
240 int result = socket_->SendTo( | 237 int result = socket_->SendTo( |
241 packet.data.get(), | 238 packet.data.get(), |
242 packet.size, | 239 packet.size, |
243 packet.to, | 240 packet.to, |
244 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); | 241 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); |
245 | 242 |
246 // sendto() may return an error, e.g. if we've received an ICMP Destination | 243 // sendto() may return an error, e.g. if we've received an ICMP Destination |
247 // Unreachable message. When this happens try sending the same packet again, | 244 // Unreachable message. When this happens try sending the same packet again, |
248 // and just drop it if it fails again. | 245 // and just drop it if it fails again. |
249 if (IsTransientError(result)) { | 246 if (IsTransientError(result)) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 case P2P_SOCKET_OPT_DSCP: | 305 case P2P_SOCKET_OPT_DSCP: |
309 return (net::OK == socket_->SetDiffServCodePoint( | 306 return (net::OK == socket_->SetDiffServCodePoint( |
310 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 307 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
311 default: | 308 default: |
312 NOTREACHED(); | 309 NOTREACHED(); |
313 return false; | 310 return false; |
314 } | 311 } |
315 } | 312 } |
316 | 313 |
317 } // namespace content | 314 } // namespace content |
OLD | NEW |