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/webrtc/base/asyncpacketsocket.h" | 18 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // UDP packets cannot be bigger than 64k. | 22 // UDP packets cannot be bigger than 64k. |
23 const int kReadBufferSize = 65536; | 23 const int kReadBufferSize = 65536; |
24 // Socket receive buffer size. | 24 // Socket receive buffer size. |
25 const int kRecvSocketBufferSize = 65536; // 64K | 25 const int kRecvSocketBufferSize = 65536; // 64K |
26 | 26 |
27 // Defines set of transient errors. These errors are ignored when we get them | 27 // Defines set of transient errors. These errors are ignored when we get them |
28 // from sendto() or recvfrom() calls. | 28 // from sendto() or recvfrom() calls. |
(...skipping 16 matching lines...) Expand all Loading... |
45 error == net::ERR_INTERNET_DISCONNECTED; | 45 error == net::ERR_INTERNET_DISCONNECTED; |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 namespace content { | 50 namespace content { |
51 | 51 |
52 P2PSocketHostUdp::PendingPacket::PendingPacket( | 52 P2PSocketHostUdp::PendingPacket::PendingPacket( |
53 const net::IPEndPoint& to, | 53 const net::IPEndPoint& to, |
54 const std::vector<char>& content, | 54 const std::vector<char>& content, |
55 const rtc::PacketOptions& options, | 55 const talk_base::PacketOptions& options, |
56 uint64 id) | 56 uint64 id) |
57 : to(to), | 57 : to(to), |
58 data(new net::IOBuffer(content.size())), | 58 data(new net::IOBuffer(content.size())), |
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() { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (dump_incoming_rtp_packet_) | 179 if (dump_incoming_rtp_packet_) |
180 DumpRtpPacket(&data[0], data.size(), true); | 180 DumpRtpPacket(&data[0], data.size(), true); |
181 } else if (result < 0 && !IsTransientError(result)) { | 181 } else if (result < 0 && !IsTransientError(result)) { |
182 LOG(ERROR) << "Error when reading from UDP socket: " << result; | 182 LOG(ERROR) << "Error when reading from UDP socket: " << result; |
183 OnError(); | 183 OnError(); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, | 187 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, |
188 const std::vector<char>& data, | 188 const std::vector<char>& data, |
189 const rtc::PacketOptions& options, | 189 const talk_base::PacketOptions& options, |
190 uint64 packet_id) { | 190 uint64 packet_id) { |
191 if (!socket_) { | 191 if (!socket_) { |
192 // The Send message may be sent after the an OnError message was | 192 // The Send message may be sent after the an OnError message was |
193 // sent by hasn't been processed the renderer. | 193 // sent by hasn't been processed the renderer. |
194 return; | 194 return; |
195 } | 195 } |
196 | 196 |
197 if (!ContainsKey(connected_peers_, to)) { | 197 if (!ContainsKey(connected_peers_, to)) { |
198 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); | 198 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); |
199 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 199 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 case P2P_SOCKET_OPT_DSCP: | 318 case P2P_SOCKET_OPT_DSCP: |
319 return (net::OK == socket_->SetDiffServCodePoint( | 319 return (net::OK == socket_->SetDiffServCodePoint( |
320 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 320 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
321 default: | 321 default: |
322 NOTREACHED(); | 322 NOTREACHED(); |
323 return false; | 323 return false; |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 } // namespace content | 327 } // namespace content |
OLD | NEW |