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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 size(content.size()), | 59 size(content.size()), |
60 packet_options(options), | 60 packet_options(options), |
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 id, |
70 P2PMessageThrottler* throttler) | 70 P2PMessageThrottler* throttler) |
71 : P2PSocketHost(message_sender, socket_id), | 71 : P2PSocketHost(message_sender, id), |
72 socket_( | 72 socket_(new net::UDPServerSocket( |
73 new net::UDPServerSocket(GetContentClient()->browser()->GetNetLog(), | 73 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) { |
82 DCHECK(socket_.get()); | 82 DCHECK(socket_.get()); |
83 socket_.reset(); | 83 socket_.reset(); |
84 } | 84 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } else if (!stun || type == STUN_DATA_INDICATION) { | 166 } else if (!stun || type == STUN_DATA_INDICATION) { |
167 LOG(ERROR) << "Received unexpected data packet from " | 167 LOG(ERROR) << "Received unexpected data packet from " |
168 << recv_address_.ToString() | 168 << recv_address_.ToString() |
169 << " before STUN binding is finished."; | 169 << " before STUN binding is finished."; |
170 return; | 170 return; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 message_sender_->Send(new P2PMsg_OnDataReceived( | 174 message_sender_->Send(new P2PMsg_OnDataReceived( |
175 id_, recv_address_, data, base::TimeTicks::Now())); | 175 id_, recv_address_, data, base::TimeTicks::Now())); |
176 | |
177 if (dump_incoming_rtp_packet_) | |
178 DumpRtpPacket(&data[0], data.size(), true); | |
179 } else if (result < 0 && !IsTransientError(result)) { | 176 } else if (result < 0 && !IsTransientError(result)) { |
180 LOG(ERROR) << "Error when reading from UDP socket: " << result; | 177 LOG(ERROR) << "Error when reading from UDP socket: " << result; |
181 OnError(); | 178 OnError(); |
182 } | 179 } |
183 } | 180 } |
184 | 181 |
185 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, | 182 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, |
186 const std::vector<char>& data, | 183 const std::vector<char>& data, |
187 const talk_base::PacketOptions& options, | 184 const talk_base::PacketOptions& options, |
188 uint64 packet_id) { | 185 uint64 packet_id) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 packet.to, | 254 packet.to, |
258 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), | 255 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), |
259 packet.id)); | 256 packet.id)); |
260 } | 257 } |
261 | 258 |
262 if (result == net::ERR_IO_PENDING) { | 259 if (result == net::ERR_IO_PENDING) { |
263 send_pending_ = true; | 260 send_pending_ = true; |
264 } else { | 261 } else { |
265 HandleSendResult(packet.id, result); | 262 HandleSendResult(packet.id, result); |
266 } | 263 } |
267 | |
268 if (dump_outgoing_rtp_packet_) | |
269 DumpRtpPacket(packet.data->data(), packet.size, false); | |
270 } | 264 } |
271 | 265 |
272 void P2PSocketHostUdp::OnSend(uint64 packet_id, int result) { | 266 void P2PSocketHostUdp::OnSend(uint64 packet_id, int result) { |
273 DCHECK(send_pending_); | 267 DCHECK(send_pending_); |
274 DCHECK_NE(result, net::ERR_IO_PENDING); | 268 DCHECK_NE(result, net::ERR_IO_PENDING); |
275 | 269 |
276 send_pending_ = false; | 270 send_pending_ = false; |
277 | 271 |
278 HandleSendResult(packet_id, result); | 272 HandleSendResult(packet_id, result); |
279 | 273 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 case P2P_SOCKET_OPT_DSCP: | 310 case P2P_SOCKET_OPT_DSCP: |
317 return (net::OK == socket_->SetDiffServCodePoint( | 311 return (net::OK == socket_->SetDiffServCodePoint( |
318 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 312 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
319 default: | 313 default: |
320 NOTREACHED(); | 314 NOTREACHED(); |
321 return false; | 315 return false; |
322 } | 316 } |
323 } | 317 } |
324 | 318 |
325 } // namespace content | 319 } // namespace content |
OLD | NEW |