| 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> |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 void FakePacketSocketFactory::SetLatency(base::TimeDelta average, | 194 void FakePacketSocketFactory::SetLatency(base::TimeDelta average, |
| 195 base::TimeDelta stddev) { | 195 base::TimeDelta stddev) { |
| 196 DCHECK(task_runner_->BelongsToCurrentThread()); | 196 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 197 latency_average_ = average; | 197 latency_average_ = average; |
| 198 latency_stddev_ = stddev; | 198 latency_stddev_ = stddev; |
| 199 } | 199 } |
| 200 | 200 |
| 201 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateUdpSocket( | 201 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateUdpSocket( |
| 202 const rtc::SocketAddress& local_address, | 202 const rtc::SocketAddress& local_address, |
| 203 int min_port, int max_port) { | 203 uint16 min_port, uint16 max_port) { |
| 204 DCHECK(task_runner_->BelongsToCurrentThread()); | 204 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 205 | 205 |
| 206 int port = -1; | 206 int port = -1; |
| 207 if (min_port > 0 && max_port > 0) { | 207 if (min_port > 0 && max_port > 0) { |
| 208 for (int i = min_port; i <= max_port; ++i) { | 208 for (uint16 i = min_port; i <= max_port; ++i) { |
| 209 if (udp_sockets_.find(i) == udp_sockets_.end()) { | 209 if (udp_sockets_.find(i) == udp_sockets_.end()) { |
| 210 port = i; | 210 port = i; |
| 211 break; | 211 break; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 if (port < 0) | 214 if (port < 0) |
| 215 return NULL; | 215 return NULL; |
| 216 } else { | 216 } else { |
| 217 do { | 217 do { |
| 218 port = next_port_; | 218 port = next_port_; |
| 219 next_port_ = | 219 next_port_ = |
| 220 (next_port_ >= kPortRangeEnd) ? kPortRangeStart : (next_port_ + 1); | 220 (next_port_ >= kPortRangeEnd) ? kPortRangeStart : (next_port_ + 1); |
| 221 } while (udp_sockets_.find(port) != udp_sockets_.end()); | 221 } while (udp_sockets_.find(port) != udp_sockets_.end()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 CHECK(local_address.ipaddr() == address_); | 224 CHECK(local_address.ipaddr() == address_); |
| 225 | 225 |
| 226 FakeUdpSocket* result = | 226 FakeUdpSocket* result = |
| 227 new FakeUdpSocket(this, dispatcher_, | 227 new FakeUdpSocket(this, dispatcher_, |
| 228 rtc::SocketAddress(local_address.ipaddr(), port)); | 228 rtc::SocketAddress(local_address.ipaddr(), port)); |
| 229 | 229 |
| 230 udp_sockets_[port] = | 230 udp_sockets_[port] = |
| 231 base::Bind(&FakeUdpSocket::ReceivePacket, base::Unretained(result)); | 231 base::Bind(&FakeUdpSocket::ReceivePacket, base::Unretained(result)); |
| 232 | 232 |
| 233 return result; | 233 return result; |
| 234 } | 234 } |
| 235 | 235 |
| 236 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateServerTcpSocket( | 236 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateServerTcpSocket( |
| 237 const rtc::SocketAddress& local_address, | 237 const rtc::SocketAddress& local_address, |
| 238 int min_port, int max_port, | 238 uint16 min_port, uint16 max_port, |
| 239 int opts) { | 239 int opts) { |
| 240 return NULL; | 240 return NULL; |
| 241 } | 241 } |
| 242 | 242 |
| 243 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateClientTcpSocket( | 243 rtc::AsyncPacketSocket* FakePacketSocketFactory::CreateClientTcpSocket( |
| 244 const rtc::SocketAddress& local_address, | 244 const rtc::SocketAddress& local_address, |
| 245 const rtc::SocketAddress& remote_address, | 245 const rtc::SocketAddress& remote_address, |
| 246 const rtc::ProxyInfo& proxy_info, | 246 const rtc::ProxyInfo& proxy_info, |
| 247 const std::string& user_agent, | 247 const std::string& user_agent, |
| 248 int opts) { | 248 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()); | 321 UdpSocketsMap::iterator iter = udp_sockets_.find(packet.to.port()); |
| 322 if (iter == udp_sockets_.end()) { | 322 if (iter == udp_sockets_.end()) { |
| 323 // Invalid port number. | 323 // Invalid port number. |
| 324 return; | 324 return; |
| 325 } | 325 } |
| 326 | 326 |
| 327 iter->second.Run(packet.from, packet.to, packet.data, packet.data_size); | 327 iter->second.Run(packet.from, packet.to, packet.data, packet.data_size); |
| 328 } | 328 } |
| 329 | 329 |
| 330 } // namespace remoting | 330 } // namespace remoting |
| OLD | NEW |