Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: remoting/test/fake_socket_factory.cc

Issue 2354263007: Minor fixes for protocol perf tests (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/test/protocol_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cmath>
11 #include <stddef.h> 11 #include <cstddef>
12 12 #include <cstdlib>
13 #include <string> 13 #include <string>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/rand_util.h" 19 #include "base/rand_util.h"
Irfan 2016/09/27 15:38:34 Do you still need the base/rand_util ? Also, what
Irfan 2016/09/27 15:39:45 duh, saw your commit message. The first Q still ho
Sergey Ulanov 2016/09/27 17:15:06 Done.
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "remoting/test/leaky_bucket.h" 24 #include "remoting/test/leaky_bucket.h"
25 #include "third_party/webrtc/base/asyncpacketsocket.h" 25 #include "third_party/webrtc/base/asyncpacketsocket.h"
26 #include "third_party/webrtc/base/socket.h" 26 #include "third_party/webrtc/base/socket.h"
27 #include "third_party/webrtc/media/base/rtputils.h" 27 #include "third_party/webrtc/media/base/rtputils.h"
28 28
29 namespace remoting { 29 namespace remoting {
30 30
31 namespace { 31 namespace {
32 32
33 const int kPortRangeStart = 1024; 33 const int kPortRangeStart = 1024;
34 const int kPortRangeEnd = 65535; 34 const int kPortRangeEnd = 65535;
35 35
36 double RandDouble() {
37 return static_cast<double>(std::rand()) / RAND_MAX;
38 }
39
36 double GetNormalRandom(double average, double stddev) { 40 double GetNormalRandom(double average, double stddev) {
37 // Based on Box-Muller transform, see 41 // Based on Box-Muller transform, see
38 // http://en.wikipedia.org/wiki/Box_Muller_transform . 42 // http://en.wikipedia.org/wiki/Box_Muller_transform .
39 return average + 43 return average +
40 stddev * sqrt(-2.0 * log(1.0 - base::RandDouble())) * 44 stddev * sqrt(-2.0 * log(1.0 - RandDouble())) *
41 cos(base::RandDouble() * 2.0 * M_PI); 45 cos(RandDouble() * 2.0 * M_PI);
42 } 46 }
43 47
44 class FakeUdpSocket : public rtc::AsyncPacketSocket { 48 class FakeUdpSocket : public rtc::AsyncPacketSocket {
45 public: 49 public:
46 FakeUdpSocket(FakePacketSocketFactory* factory, 50 FakeUdpSocket(FakePacketSocketFactory* factory,
47 scoped_refptr<FakeNetworkDispatcher> dispatcher, 51 scoped_refptr<FakeNetworkDispatcher> dispatcher,
48 const rtc::SocketAddress& local_address); 52 const rtc::SocketAddress& local_address);
49 ~FakeUdpSocket() override; 53 ~FakeUdpSocket() override;
50 54
51 void ReceivePacket(const rtc::SocketAddress& from, 55 void ReceivePacket(const rtc::SocketAddress& from,
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 FROM_HERE, 325 FROM_HERE,
322 base::Bind(&FakePacketSocketFactory::DoReceivePacket, 326 base::Bind(&FakePacketSocketFactory::DoReceivePacket,
323 weak_factory_.GetWeakPtr()), 327 weak_factory_.GetWeakPtr()),
324 delay); 328 delay);
325 } 329 }
326 330
327 void FakePacketSocketFactory::DoReceivePacket() { 331 void FakePacketSocketFactory::DoReceivePacket() {
328 DCHECK(task_runner_->BelongsToCurrentThread()); 332 DCHECK(task_runner_->BelongsToCurrentThread());
329 333
330 PendingPacket packet; 334 PendingPacket packet;
331 if (pending_packets_.size() > 1 && base::RandDouble() < out_of_order_rate_) { 335 if (pending_packets_.size() > 1 && RandDouble() < out_of_order_rate_) {
332 std::list<PendingPacket>::iterator it = pending_packets_.begin(); 336 std::list<PendingPacket>::iterator it = pending_packets_.begin();
333 ++it; 337 ++it;
334 packet = *it; 338 packet = *it;
335 pending_packets_.erase(it); 339 pending_packets_.erase(it);
336 } else { 340 } else {
337 packet = pending_packets_.front(); 341 packet = pending_packets_.front();
338 pending_packets_.pop_front(); 342 pending_packets_.pop_front();
339 } 343 }
340 344
341 UdpSocketsMap::iterator iter = udp_sockets_.find(packet.to.port()); 345 UdpSocketsMap::iterator iter = udp_sockets_.find(packet.to.port());
342 if (iter == udp_sockets_.end()) { 346 if (iter == udp_sockets_.end()) {
343 // Invalid port number. 347 // Invalid port number.
344 return; 348 return;
345 } 349 }
346 350
347 iter->second.Run(packet.from, packet.to, packet.data, packet.data_size); 351 iter->second.Run(packet.from, packet.to, packet.data, packet.data_size);
348 } 352 }
349 353
350 } // namespace remoting 354 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/test/protocol_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698