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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, | 68 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, |
69 int socket_id, | 69 int socket_id, |
70 P2PMessageThrottler* throttler) | 70 P2PMessageThrottler* throttler) |
71 : P2PSocketHost(message_sender, socket_id), | 71 : P2PSocketHost(message_sender, socket_id), |
72 socket_( | 72 socket_( |
73 new net::UDPServerSocket(GetContentClient()->browser()->GetNetLog(), | 73 new net::UDPServerSocket(GetContentClient()->browser()->GetNetLog(), |
74 net::NetLog::Source())), | 74 net::NetLog::Source())), |
75 send_pending_(false), | 75 send_pending_(false), |
76 last_dscp_(net::DSCP_CS0), | 76 last_dscp_(net::DSCP_CS0), |
77 throttler_(throttler) { | 77 throttler_(throttler) { |
78 protocol_type_ = P2PSocketHost::UDP; | |
78 } | 79 } |
79 | 80 |
80 P2PSocketHostUdp::~P2PSocketHostUdp() { | 81 P2PSocketHostUdp::~P2PSocketHostUdp() { |
81 if (state_ == STATE_OPEN) { | 82 if (state_ == STATE_OPEN) { |
82 DCHECK(socket_.get()); | 83 DCHECK(socket_.get()); |
83 socket_.reset(); | 84 socket_.reset(); |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 bool P2PSocketHostUdp::Init(const net::IPEndPoint& local_address, | 88 bool P2PSocketHostUdp::Init(const net::IPEndPoint& local_address, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 | 207 |
207 if (throttler_->DropNextPacket(data.size())) { | 208 if (throttler_->DropNextPacket(data.size())) { |
208 VLOG(0) << "STUN message is dropped due to high volume."; | 209 VLOG(0) << "STUN message is dropped due to high volume."; |
209 // Do not reset socket. | 210 // Do not reset socket. |
210 return; | 211 return; |
211 } | 212 } |
212 } | 213 } |
213 | 214 |
214 if (send_pending_) { | 215 if (send_pending_) { |
215 send_queue_.push_back(PendingPacket(to, data, options, packet_id)); | 216 send_queue_.push_back(PendingPacket(to, data, options, packet_id)); |
217 if (send_queue_.size() > send_queue_length_max_) { | |
218 send_queue_length_max_ = send_queue_.size(); | |
219 } | |
216 } else { | 220 } else { |
217 // TODO(mallinath: Remove unnecessary memcpy in this case. | 221 // TODO(mallinath: Remove unnecessary memcpy in this case. |
218 PendingPacket packet(to, data, options, packet_id); | 222 PendingPacket packet(to, data, options, packet_id); |
219 DoSend(packet); | 223 DoSend(packet); |
220 } | 224 } |
221 } | 225 } |
222 | 226 |
223 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { | 227 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { |
224 TRACE_EVENT_ASYNC_STEP_INTO1("p2p", "Send", packet.id, "UdpAsyncSendTo", | 228 TRACE_EVENT_ASYNC_STEP_INTO1("p2p", "Send", packet.id, "UdpAsyncSendTo", |
225 "size", packet.size); | 229 "size", packet.size); |
(...skipping 20 matching lines...) Expand all Loading... | |
246 int result = socket_->SendTo( | 250 int result = socket_->SendTo( |
247 packet.data.get(), | 251 packet.data.get(), |
248 packet.size, | 252 packet.size, |
249 packet.to, | 253 packet.to, |
250 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); | 254 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); |
251 | 255 |
252 // sendto() may return an error, e.g. if we've received an ICMP Destination | 256 // sendto() may return an error, e.g. if we've received an ICMP Destination |
253 // Unreachable message. When this happens try sending the same packet again, | 257 // Unreachable message. When this happens try sending the same packet again, |
254 // and just drop it if it fails again. | 258 // and just drop it if it fails again. |
255 if (IsTransientError(result)) { | 259 if (IsTransientError(result)) { |
256 result = socket_->SendTo( | 260 result = socket_->SendTo( |
juberti2
2014/10/23 19:38:46
If I understand this code right, we will never ret
guoweis2
2014/10/24 06:08:54
The code should send synchronously most of the tim
| |
257 packet.data.get(), | 261 packet.data.get(), |
258 packet.size, | 262 packet.size, |
259 packet.to, | 263 packet.to, |
260 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), | 264 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), |
261 packet.id)); | 265 packet.id)); |
262 } | 266 } |
263 | 267 |
264 if (result == net::ERR_IO_PENDING) { | 268 if (result == net::ERR_IO_PENDING) { |
265 send_pending_ = true; | 269 send_pending_ = true; |
266 } else { | 270 } else { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 case P2P_SOCKET_OPT_DSCP: | 322 case P2P_SOCKET_OPT_DSCP: |
319 return (net::OK == socket_->SetDiffServCodePoint( | 323 return (net::OK == socket_->SetDiffServCodePoint( |
320 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 324 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
321 default: | 325 default: |
322 NOTREACHED(); | 326 NOTREACHED(); |
323 return false; | 327 return false; |
324 } | 328 } |
325 } | 329 } |
326 | 330 |
327 } // namespace content | 331 } // namespace content |
OLD | NEW |