This CL was generated by running git ls-files | grep -P "(\.h|\.cc)$" | grep -v 'sdk/' | grep -v 'rtc_base/ssl_' | \ grep -v 'fake_rtc_certificate_generator.h' | grep -v 'modules/audio_device/win/' | \ grep -v 'system_wrappers/source/clock.cc' | grep -v 'rtc_base/trace_event.h' | \ grep -v 'modules/audio_coding/codecs/ilbc/' | grep -v 'screen_capturer_mac.h' | \ grep -v 'spl_inl_mips.h' | grep -v 'data_size_unittest.cc' | grep -v 'timestamp_unittest.cc' \ | xargs clang-format -i ; git cl format Most of these changes are clang-format grouping and reordering includes differently. Bug: webrtc:9340 Change-Id: Ic83ddbc169bfacd21883e381b5181c3dd4fe8a63 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144051 Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28505}
95 lines
2.7 KiB
C++
95 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "test/network/fake_network_socket_server.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "rtc_base/thread.h"
|
|
|
|
namespace webrtc {
|
|
namespace test {
|
|
|
|
FakeNetworkSocketServer::FakeNetworkSocketServer(
|
|
Clock* clock,
|
|
EndpointsContainer* endpoints_container)
|
|
: clock_(clock),
|
|
endpoints_container_(endpoints_container),
|
|
wakeup_(/*manual_reset=*/false, /*initially_signaled=*/false) {}
|
|
FakeNetworkSocketServer::~FakeNetworkSocketServer() = default;
|
|
|
|
void FakeNetworkSocketServer::OnMessageQueueDestroyed() {
|
|
msg_queue_ = nullptr;
|
|
}
|
|
|
|
EmulatedEndpoint* FakeNetworkSocketServer::GetEndpointNode(
|
|
const rtc::IPAddress& ip) {
|
|
return endpoints_container_->LookupByLocalAddress(ip);
|
|
}
|
|
|
|
void FakeNetworkSocketServer::Unregister(SocketIoProcessor* io_processor) {
|
|
rtc::CritScope crit(&lock_);
|
|
io_processors_.erase(io_processor);
|
|
}
|
|
|
|
rtc::Socket* FakeNetworkSocketServer::CreateSocket(int /*family*/,
|
|
int /*type*/) {
|
|
RTC_CHECK(false) << "Only async sockets are supported";
|
|
}
|
|
|
|
rtc::AsyncSocket* FakeNetworkSocketServer::CreateAsyncSocket(int family,
|
|
int type) {
|
|
RTC_DCHECK(family == AF_INET || family == AF_INET6);
|
|
// We support only UDP sockets for now.
|
|
RTC_DCHECK(type == SOCK_DGRAM) << "Only UDP sockets are supported";
|
|
FakeNetworkSocket* out = new FakeNetworkSocket(this);
|
|
{
|
|
rtc::CritScope crit(&lock_);
|
|
io_processors_.insert(out);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
void FakeNetworkSocketServer::SetMessageQueue(rtc::MessageQueue* msg_queue) {
|
|
msg_queue_ = msg_queue;
|
|
if (msg_queue_) {
|
|
msg_queue_->SignalQueueDestroyed.connect(
|
|
this, &FakeNetworkSocketServer::OnMessageQueueDestroyed);
|
|
}
|
|
}
|
|
|
|
// Always returns true (if return false, it won't be invoked again...)
|
|
bool FakeNetworkSocketServer::Wait(int cms, bool process_io) {
|
|
RTC_DCHECK(msg_queue_ == rtc::Thread::Current());
|
|
if (!process_io) {
|
|
wakeup_.Wait(cms);
|
|
return true;
|
|
}
|
|
wakeup_.Wait(cms);
|
|
|
|
rtc::CritScope crit(&lock_);
|
|
for (auto* io_processor : io_processors_) {
|
|
while (io_processor->ProcessIo()) {
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void FakeNetworkSocketServer::WakeUp() {
|
|
wakeup_.Set();
|
|
}
|
|
|
|
Timestamp FakeNetworkSocketServer::Now() const {
|
|
return clock_->CurrentTime();
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace webrtc
|