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

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

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/virtualsocketserver.h ('k') | no next file » | 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 #include "webrtc/base/virtualsocketserver.h" 11 #include "webrtc/base/virtualsocketserver.h"
12 12
13 #include <errno.h> 13 #include <errno.h>
14 #include <math.h> 14 #include <math.h>
15 15
16 #include <algorithm> 16 #include <algorithm>
17 #include <map> 17 #include <map>
18 #include <memory> 18 #include <memory>
19 #include <vector> 19 #include <vector>
20 20
21 #include "webrtc/base/checks.h" 21 #include "webrtc/base/checks.h"
22 #include "webrtc/base/gunit.h"
22 #include "webrtc/base/logging.h" 23 #include "webrtc/base/logging.h"
23 #include "webrtc/base/physicalsocketserver.h" 24 #include "webrtc/base/physicalsocketserver.h"
24 #include "webrtc/base/socketaddresspair.h" 25 #include "webrtc/base/socketaddresspair.h"
25 #include "webrtc/base/thread.h" 26 #include "webrtc/base/thread.h"
26 #include "webrtc/base/timeutils.h" 27 #include "webrtc/base/timeutils.h"
27 28
28 namespace rtc { 29 namespace rtc {
29 #if defined(WEBRTC_WIN) 30 #if defined(WEBRTC_WIN)
30 const in_addr kInitialNextIPv4 = { { { 0x01, 0, 0, 0 } } }; 31 const in_addr kInitialNextIPv4 = { { { 0x01, 0, 0, 0 } } };
31 #else 32 #else
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 ready_to_send_ = true; 522 ready_to_send_ = true;
522 SignalWriteEvent(this); 523 SignalWriteEvent(this);
523 } else { 524 } else {
524 RTC_DCHECK(type_ == SOCK_STREAM); 525 RTC_DCHECK(type_ == SOCK_STREAM);
525 // This will attempt to empty the full send buffer, and will fire 526 // This will attempt to empty the full send buffer, and will fire
526 // SignalWriteEvent if successful. 527 // SignalWriteEvent if successful.
527 server_->SendTcp(this); 528 server_->SendTcp(this);
528 } 529 }
529 } 530 }
530 531
531 VirtualSocketServer::VirtualSocketServer() 532 VirtualSocketServer::VirtualSocketServer() : VirtualSocketServer(nullptr) {}
532 : wakeup_(/*manual_reset=*/false, /*initially_signaled=*/false), 533
534 VirtualSocketServer::VirtualSocketServer(FakeClock* fake_clock)
535 : fake_clock_(fake_clock),
536 wakeup_(/*manual_reset=*/false, /*initially_signaled=*/false),
533 msg_queue_(nullptr), 537 msg_queue_(nullptr),
534 stop_on_idle_(false), 538 stop_on_idle_(false),
535 next_ipv4_(kInitialNextIPv4), 539 next_ipv4_(kInitialNextIPv4),
536 next_ipv6_(kInitialNextIPv6), 540 next_ipv6_(kInitialNextIPv6),
537 next_port_(kFirstEphemeralPort), 541 next_port_(kFirstEphemeralPort),
538 bindings_(new AddressMap()), 542 bindings_(new AddressMap()),
539 connections_(new ConnectionMap()), 543 connections_(new ConnectionMap()),
540 bandwidth_(0), 544 bandwidth_(0),
541 network_capacity_(kDefaultNetworkCapacity), 545 network_capacity_(kDefaultNetworkCapacity),
542 send_buffer_capacity_(kDefaultTcpBufferSize), 546 send_buffer_capacity_(kDefaultTcpBufferSize),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 639 }
636 640
637 void VirtualSocketServer::WakeUp() { 641 void VirtualSocketServer::WakeUp() {
638 wakeup_.Set(); 642 wakeup_.Set();
639 } 643 }
640 644
641 bool VirtualSocketServer::ProcessMessagesUntilIdle() { 645 bool VirtualSocketServer::ProcessMessagesUntilIdle() {
642 RTC_DCHECK(msg_queue_ == Thread::Current()); 646 RTC_DCHECK(msg_queue_ == Thread::Current());
643 stop_on_idle_ = true; 647 stop_on_idle_ = true;
644 while (!msg_queue_->empty()) { 648 while (!msg_queue_->empty()) {
645 Message msg; 649 if (fake_clock_) {
646 if (msg_queue_->Get(&msg, Thread::kForever)) { 650 // If using a fake clock, advance it in millisecond increments until the
647 msg_queue_->Dispatch(&msg); 651 // queue is empty (the SIMULATED_WAIT macro ensures the queue processes
652 // all possible messages each time it's called).
653 SIMULATED_WAIT(false, 1, *fake_clock_);
654 } else {
655 // Otherwise, run a normal message loop.
656 Message msg;
657 if (msg_queue_->Get(&msg, Thread::kForever)) {
658 msg_queue_->Dispatch(&msg);
659 }
648 } 660 }
649 } 661 }
650 stop_on_idle_ = false; 662 stop_on_idle_ = false;
651 return !msg_queue_->IsQuitting(); 663 return !msg_queue_->IsQuitting();
652 } 664 }
653 665
654 void VirtualSocketServer::SetNextPortForTesting(uint16_t port) { 666 void VirtualSocketServer::SetNextPortForTesting(uint16_t port) {
655 next_port_ = port; 667 next_port_ = port;
656 } 668 }
657 669
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) { 1205 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) {
1194 RTC_DCHECK(!IPIsAny(from_addr)); 1206 RTC_DCHECK(!IPIsAny(from_addr));
1195 if (from_addr.family() == AF_INET) { 1207 if (from_addr.family() == AF_INET) {
1196 default_route_v4_ = from_addr; 1208 default_route_v4_ = from_addr;
1197 } else if (from_addr.family() == AF_INET6) { 1209 } else if (from_addr.family() == AF_INET6) {
1198 default_route_v6_ = from_addr; 1210 default_route_v6_ = from_addr;
1199 } 1211 }
1200 } 1212 }
1201 1213
1202 } // namespace rtc 1214 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/virtualsocketserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698