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

Side by Side Diff: webrtc/base/virtualsocketserver.h

Issue 2927413002: Update VirtualSocketServerTest to use a fake clock. (Closed)
Patch Set: Allow ProcessMessages with cmsLoop of kForever. Created 3 years, 6 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 | « webrtc/base/virtualsocket_unittest.cc ('k') | webrtc/base/virtualsocketserver.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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ 11 #ifndef WEBRTC_BASE_VIRTUALSOCKETSERVER_H_
12 #define WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ 12 #define WEBRTC_BASE_VIRTUALSOCKETSERVER_H_
13 13
14 #include <deque> 14 #include <deque>
15 #include <map> 15 #include <map>
16 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/constructormagic.h" 18 #include "webrtc/base/constructormagic.h"
19 #include "webrtc/base/event.h" 19 #include "webrtc/base/event.h"
20 #include "webrtc/base/fakeclock.h"
20 #include "webrtc/base/messagequeue.h" 21 #include "webrtc/base/messagequeue.h"
21 #include "webrtc/base/socketserver.h" 22 #include "webrtc/base/socketserver.h"
22 23
23 namespace rtc { 24 namespace rtc {
24 25
25 class Packet; 26 class Packet;
26 class VirtualSocket; 27 class VirtualSocket;
27 class SocketAddressPair; 28 class SocketAddressPair;
28 29
29 // Simulates a network in the same manner as a loopback interface. The 30 // Simulates a network in the same manner as a loopback interface. The
30 // interface can create as many addresses as you want. All of the sockets 31 // interface can create as many addresses as you want. All of the sockets
31 // created by this network will be able to communicate with one another, unless 32 // created by this network will be able to communicate with one another, unless
32 // they are bound to addresses from incompatible families. 33 // they are bound to addresses from incompatible families.
33 class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> { 34 class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> {
34 public: 35 public:
35 VirtualSocketServer(); 36 VirtualSocketServer();
37 // This constructor needs to be used if the test uses a fake clock and
38 // ProcessMessagesUntilIdle, since ProcessMessagesUntilIdle needs a way of
39 // advancing time.
40 explicit VirtualSocketServer(FakeClock* fake_clock);
36 ~VirtualSocketServer() override; 41 ~VirtualSocketServer() override;
37 42
38 // The default route indicates which local address to use when a socket is 43 // The default route indicates which local address to use when a socket is
39 // bound to the 'any' address, e.g. 0.0.0.0. 44 // bound to the 'any' address, e.g. 0.0.0.0.
40 IPAddress GetDefaultRoute(int family); 45 IPAddress GetDefaultRoute(int family);
41 void SetDefaultRoute(const IPAddress& from_addr); 46 void SetDefaultRoute(const IPAddress& from_addr);
42 47
43 // Limits the network bandwidth (maximum bytes per second). Zero means that 48 // Limits the network bandwidth (maximum bytes per second). Zero means that
44 // all sends occur instantly. Defaults to 0. 49 // all sends occur instantly. Defaults to 0.
45 uint32_t bandwidth() const { return bandwidth_; } 50 uint32_t bandwidth() const { return bandwidth_; }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 240
236 private: 241 private:
237 friend class VirtualSocket; 242 friend class VirtualSocket;
238 243
239 // Sending was previously blocked, but now isn't. 244 // Sending was previously blocked, but now isn't.
240 sigslot::signal0<> SignalReadyToSend; 245 sigslot::signal0<> SignalReadyToSend;
241 246
242 typedef std::map<SocketAddress, VirtualSocket*> AddressMap; 247 typedef std::map<SocketAddress, VirtualSocket*> AddressMap;
243 typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap; 248 typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap;
244 249
250 // May be null if the test doesn't use a fake clock, or it does but doesn't
251 // use ProcessMessagesUntilIdle.
252 FakeClock* fake_clock_ = nullptr;
253
245 // Used to implement Wait/WakeUp. 254 // Used to implement Wait/WakeUp.
246 Event wakeup_; 255 Event wakeup_;
247 MessageQueue* msg_queue_; 256 MessageQueue* msg_queue_;
248 bool stop_on_idle_; 257 bool stop_on_idle_;
249 in_addr next_ipv4_; 258 in_addr next_ipv4_;
250 in6_addr next_ipv6_; 259 in6_addr next_ipv6_;
251 uint16_t next_port_; 260 uint16_t next_port_;
252 AddressMap* bindings_; 261 AddressMap* bindings_;
253 ConnectionMap* connections_; 262 ConnectionMap* connections_;
254 263
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 391
383 // Store the options that are set 392 // Store the options that are set
384 OptionsMap options_map_; 393 OptionsMap options_map_;
385 394
386 friend class VirtualSocketServer; 395 friend class VirtualSocketServer;
387 }; 396 };
388 397
389 } // namespace rtc 398 } // namespace rtc
390 399
391 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ 400 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_
OLDNEW
« no previous file with comments | « webrtc/base/virtualsocket_unittest.cc ('k') | webrtc/base/virtualsocketserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698