OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "remoting/test/fake_socket_factory.h" | 8 #include "remoting/test/fake_socket_factory.h" |
9 | 9 |
10 #include <math.h> | 10 #include <math.h> |
| 11 #include <stddef.h> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" |
15 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
16 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
17 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
18 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
19 #include "remoting/test/leaky_bucket.h" | 21 #include "remoting/test/leaky_bucket.h" |
20 #include "third_party/webrtc/base/asyncpacketsocket.h" | 22 #include "third_party/webrtc/base/asyncpacketsocket.h" |
21 | 23 |
22 namespace remoting { | 24 namespace remoting { |
23 | 25 |
24 namespace { | 26 namespace { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 195 |
194 void FakePacketSocketFactory::SetLatency(base::TimeDelta average, | 196 void FakePacketSocketFactory::SetLatency(base::TimeDelta average, |
195 base::TimeDelta stddev) { | 197 base::TimeDelta stddev) { |
196 DCHECK(task_runner_->BelongsToCurrentThread()); | 198 DCHECK(task_runner_->BelongsToCurrentThread()); |
197 latency_average_ = average; | 199 latency_average_ = average; |
198 latency_stddev_ = stddev; | 200 latency_stddev_ = stddev; |
199 } | 201 } |
200 | 202 |
201 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateUdpSocket( | 203 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateUdpSocket( |
202 const rtc::SocketAddress& local_address, | 204 const rtc::SocketAddress& local_address, |
203 uint16 min_port, uint16 max_port) { | 205 uint16_t min_port, |
| 206 uint16_t max_port) { |
204 DCHECK(task_runner_->BelongsToCurrentThread()); | 207 DCHECK(task_runner_->BelongsToCurrentThread()); |
205 | 208 |
206 int port = -1; | 209 int port = -1; |
207 if (min_port > 0 && max_port > 0) { | 210 if (min_port > 0 && max_port > 0) { |
208 for (uint16 i = min_port; i <= max_port; ++i) { | 211 for (uint16_t i = min_port; i <= max_port; ++i) { |
209 if (udp_sockets_.find(i) == udp_sockets_.end()) { | 212 if (udp_sockets_.find(i) == udp_sockets_.end()) { |
210 port = i; | 213 port = i; |
211 break; | 214 break; |
212 } | 215 } |
213 } | 216 } |
214 if (port < 0) | 217 if (port < 0) |
215 return nullptr; | 218 return nullptr; |
216 } else { | 219 } else { |
217 do { | 220 do { |
218 port = next_port_; | 221 port = next_port_; |
219 next_port_ = | 222 next_port_ = |
220 (next_port_ >= kPortRangeEnd) ? kPortRangeStart : (next_port_ + 1); | 223 (next_port_ >= kPortRangeEnd) ? kPortRangeStart : (next_port_ + 1); |
221 } while (udp_sockets_.find(port) != udp_sockets_.end()); | 224 } while (udp_sockets_.find(port) != udp_sockets_.end()); |
222 } | 225 } |
223 | 226 |
224 CHECK(local_address.ipaddr() == address_); | 227 CHECK(local_address.ipaddr() == address_); |
225 | 228 |
226 FakeUdpSocket* result = | 229 FakeUdpSocket* result = |
227 new FakeUdpSocket(this, dispatcher_, | 230 new FakeUdpSocket(this, dispatcher_, |
228 rtc::SocketAddress(local_address.ipaddr(), port)); | 231 rtc::SocketAddress(local_address.ipaddr(), port)); |
229 | 232 |
230 udp_sockets_[port] = | 233 udp_sockets_[port] = |
231 base::Bind(&FakeUdpSocket::ReceivePacket, base::Unretained(result)); | 234 base::Bind(&FakeUdpSocket::ReceivePacket, base::Unretained(result)); |
232 | 235 |
233 return result; | 236 return result; |
234 } | 237 } |
235 | 238 |
236 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateServerTcpSocket( | 239 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateServerTcpSocket( |
237 const rtc::SocketAddress& local_address, | 240 const rtc::SocketAddress& local_address, |
238 uint16 min_port, uint16 max_port, | 241 uint16_t min_port, |
| 242 uint16_t max_port, |
239 int opts) { | 243 int opts) { |
240 return nullptr; | 244 return nullptr; |
241 } | 245 } |
242 | 246 |
243 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateClientTcpSocket( | 247 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateClientTcpSocket( |
244 const rtc::SocketAddress& local_address, | 248 const rtc::SocketAddress& local_address, |
245 const rtc::SocketAddress& remote_address, | 249 const rtc::SocketAddress& remote_address, |
246 const rtc::ProxyInfo& proxy_info, | 250 const rtc::ProxyInfo& proxy_info, |
247 const std::string& user_agent, | 251 const std::string& user_agent, |
248 int opts) { | 252 int opts) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 UdpSocketsMap::iterator iter = udp_sockets_.find(packet.to.port()); | 325 UdpSocketsMap::iterator iter = udp_sockets_.find(packet.to.port()); |
322 if (iter == udp_sockets_.end()) { | 326 if (iter == udp_sockets_.end()) { |
323 // Invalid port number. | 327 // Invalid port number. |
324 return; | 328 return; |
325 } | 329 } |
326 | 330 |
327 iter->second.Run(packet.from, packet.to, packet.data, packet.data_size); | 331 iter->second.Run(packet.from, packet.to, packet.data, packet.data_size); |
328 } | 332 } |
329 | 333 |
330 } // namespace remoting | 334 } // namespace remoting |
OLD | NEW |