blob: 68624a77911ce8ed7585b23fd22778ba6e072b26 [file] [log] [blame]
Artem Titov0774bd92019-01-30 14:26:051/*
2 * Copyright (c) 2019 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 */
10
Artem Titov386802e2019-07-05 08:48:1711#ifndef TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_
12#define TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_
Artem Titov0774bd92019-01-30 14:26:0513
14#include <set>
15#include <vector>
16
17#include "api/units/timestamp.h"
Artem Titov0774bd92019-01-30 14:26:0518#include "rtc_base/event.h"
Niels Möllerd0b88792021-08-12 08:32:3019#include "rtc_base/socket.h"
Artem Titov0774bd92019-01-30 14:26:0520#include "rtc_base/socket_server.h"
Markus Handella5a4be12020-07-08 14:09:2121#include "rtc_base/synchronization/mutex.h"
Artem Titov0774bd92019-01-30 14:26:0522#include "system_wrappers/include/clock.h"
Sebastian Janssona406ee12020-01-07 16:52:2423#include "test/network/network_emulation.h"
Artem Titov0774bd92019-01-30 14:26:0524
25namespace webrtc {
26namespace test {
Sebastian Janssona406ee12020-01-07 16:52:2427class FakeNetworkSocket;
Artem Titov0774bd92019-01-30 14:26:0528
29// FakeNetworkSocketServer must outlive any sockets it creates.
Niels Möller9bd24572021-04-19 10:18:2730class FakeNetworkSocketServer : public rtc::SocketServer {
Artem Titov0774bd92019-01-30 14:26:0531 public:
Sebastian Jansson9d4bbc22020-01-10 19:03:5632 explicit FakeNetworkSocketServer(EndpointsContainer* endpoints_controller);
Artem Titov0774bd92019-01-30 14:26:0533 ~FakeNetworkSocketServer() override;
34
Artem Titov0774bd92019-01-30 14:26:0535 // rtc::SocketFactory methods:
36 rtc::Socket* CreateSocket(int family, int type) override;
Artem Titov0774bd92019-01-30 14:26:0537
38 // rtc::SocketServer methods:
39 // Called by the network thread when this server is installed, kicking off the
40 // message handler loop.
Sebastian Jansson9d4bbc22020-01-10 19:03:5641 void SetMessageQueue(rtc::Thread* thread) override;
Markus Handell9a21c492022-08-25 11:40:1342 bool Wait(webrtc::TimeDelta max_wait_duration, bool process_io) override;
Artem Titov0774bd92019-01-30 14:26:0543 void WakeUp() override;
44
Sebastian Jansson9d4bbc22020-01-10 19:03:5645 protected:
46 friend class FakeNetworkSocket;
47 EmulatedEndpointImpl* GetEndpointNode(const rtc::IPAddress& ip);
48 void Unregister(FakeNetworkSocket* socket);
Artem Titov0774bd92019-01-30 14:26:0549
Sebastian Jansson9d4bbc22020-01-10 19:03:5650 private:
Artem Titove5cc85b2019-03-28 11:11:0951 const EndpointsContainer* endpoints_container_;
Artem Titov0774bd92019-01-30 14:26:0552 rtc::Event wakeup_;
Sebastian Jansson9d4bbc22020-01-10 19:03:5653 rtc::Thread* thread_ = nullptr;
Artem Titov0774bd92019-01-30 14:26:0554
Markus Handella5a4be12020-07-08 14:09:2155 Mutex lock_;
Sebastian Janssona406ee12020-01-07 16:52:2456 std::vector<FakeNetworkSocket*> sockets_ RTC_GUARDED_BY(lock_);
Artem Titov0774bd92019-01-30 14:26:0557};
58
59} // namespace test
60} // namespace webrtc
61
Artem Titov386802e2019-07-05 08:48:1762#endif // TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_