blob: 643da5d56e2ada130b3cba1db1afce1e541c0df1 [file] [log] [blame]
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#include "test/run_loop.h"
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +000011
Tommi9e46cf52020-05-04 16:43:05 +020012#include "rtc_base/task_utils/to_queued_task.h"
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +000013
14namespace webrtc {
15namespace test {
16
Tommi9e46cf52020-05-04 16:43:05 +020017RunLoop::RunLoop() {
18 worker_thread_.WrapCurrent();
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +000019}
Tommi9e46cf52020-05-04 16:43:05 +020020
21RunLoop::~RunLoop() {
22 worker_thread_.UnwrapCurrent();
23}
24
25TaskQueueBase* RunLoop::task_queue() {
26 return &worker_thread_;
27}
28
29void RunLoop::Run() {
30 worker_thread_.ProcessMessages(WorkerThread::kForever);
31}
32
33void RunLoop::Quit() {
34 socket_server_.FailNextWait();
35}
36
37void RunLoop::Flush() {
38 worker_thread_.PostTask(
39 ToQueuedTask([this]() { socket_server_.FailNextWait(); }));
40 worker_thread_.ProcessMessages(1000);
41}
42
43RunLoop::FakeSocketServer::FakeSocketServer() = default;
44RunLoop::FakeSocketServer::~FakeSocketServer() = default;
45
46void RunLoop::FakeSocketServer::FailNextWait() {
47 fail_next_wait_ = true;
48}
49
50bool RunLoop::FakeSocketServer::Wait(int cms, bool process_io) {
51 if (fail_next_wait_) {
52 fail_next_wait_ = false;
53 return false;
54 }
55 return true;
56}
57
58void RunLoop::FakeSocketServer::WakeUp() {}
59
60rtc::Socket* RunLoop::FakeSocketServer::CreateSocket(int family, int type) {
61 return nullptr;
62}
63
64rtc::AsyncSocket* RunLoop::FakeSocketServer::CreateAsyncSocket(int family,
65 int type) {
66 return nullptr;
67}
68
69RunLoop::WorkerThread::WorkerThread(rtc::SocketServer* ss)
70 : rtc::Thread(ss), tq_setter_(this) {}
71
pbos@webrtc.orgadf23a52013-07-10 14:07:56 +000072} // namespace test
73} // namespace webrtc