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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 id(id) { | 61 id(id) { |
62 memcpy(data->data(), &content[0], size); | 62 memcpy(data->data(), &content[0], size); |
63 } | 63 } |
64 | 64 |
65 P2PSocketHostUdp::PendingPacket::~PendingPacket() { | 65 P2PSocketHostUdp::PendingPacket::~PendingPacket() { |
66 } | 66 } |
67 | 67 |
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, P2PSocketHost::UDP), |
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 } | 78 } |
79 | 79 |
80 P2PSocketHostUdp::~P2PSocketHostUdp() { | 80 P2PSocketHostUdp::~P2PSocketHostUdp() { |
81 if (state_ == STATE_OPEN) { | 81 if (state_ == STATE_OPEN) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return; | 204 return; |
205 } | 205 } |
206 | 206 |
207 if (throttler_->DropNextPacket(data.size())) { | 207 if (throttler_->DropNextPacket(data.size())) { |
208 VLOG(0) << "STUN message is dropped due to high volume."; | 208 VLOG(0) << "STUN message is dropped due to high volume."; |
209 // Do not reset socket. | 209 // Do not reset socket. |
210 return; | 210 return; |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
| 214 IncrementTotalSentPackets(); |
| 215 |
214 if (send_pending_) { | 216 if (send_pending_) { |
215 send_queue_.push_back(PendingPacket(to, data, options, packet_id)); | 217 send_queue_.push_back(PendingPacket(to, data, options, packet_id)); |
| 218 IncrementDelayedBytes(data.size()); |
| 219 IncrementDelayedPackets(); |
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 void P2PSocketHostUdp::OnSend(uint64 packet_id, int result) { | 278 void P2PSocketHostUdp::OnSend(uint64 packet_id, int result) { |
275 DCHECK(send_pending_); | 279 DCHECK(send_pending_); |
276 DCHECK_NE(result, net::ERR_IO_PENDING); | 280 DCHECK_NE(result, net::ERR_IO_PENDING); |
277 | 281 |
278 send_pending_ = false; | 282 send_pending_ = false; |
279 | 283 |
280 HandleSendResult(packet_id, result); | 284 HandleSendResult(packet_id, result); |
281 | 285 |
282 // Send next packets if we have them waiting in the buffer. | 286 // Send next packets if we have them waiting in the buffer. |
283 while (state_ == STATE_OPEN && !send_queue_.empty() && !send_pending_) { | 287 while (state_ == STATE_OPEN && !send_queue_.empty() && !send_pending_) { |
284 DoSend(send_queue_.front()); | 288 PendingPacket packet = send_queue_.front(); |
| 289 DoSend(packet); |
285 send_queue_.pop_front(); | 290 send_queue_.pop_front(); |
| 291 DecrementDelayedBytes(packet.size); |
286 } | 292 } |
287 } | 293 } |
288 | 294 |
289 void P2PSocketHostUdp::HandleSendResult(uint64 packet_id, int result) { | 295 void P2PSocketHostUdp::HandleSendResult(uint64 packet_id, int result) { |
290 TRACE_EVENT_ASYNC_END1("p2p", "Send", packet_id, | 296 TRACE_EVENT_ASYNC_END1("p2p", "Send", packet_id, |
291 "result", result); | 297 "result", result); |
292 if (result < 0) { | 298 if (result < 0) { |
293 if (!IsTransientError(result)) { | 299 if (!IsTransientError(result)) { |
294 LOG(ERROR) << "Error when sending data in UDP socket: " << result; | 300 LOG(ERROR) << "Error when sending data in UDP socket: " << result; |
295 OnError(); | 301 OnError(); |
(...skipping 22 matching lines...) Expand all Loading... |
318 case P2P_SOCKET_OPT_DSCP: | 324 case P2P_SOCKET_OPT_DSCP: |
319 return (net::OK == socket_->SetDiffServCodePoint( | 325 return (net::OK == socket_->SetDiffServCodePoint( |
320 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 326 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
321 default: | 327 default: |
322 NOTREACHED(); | 328 NOTREACHED(); |
323 return false; | 329 return false; |
324 } | 330 } |
325 } | 331 } |
326 | 332 |
327 } // namespace content | 333 } // namespace content |
OLD | NEW |