2019-01-30 15:26:05 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-07-05 10:48:17 +02:00
|
|
|
#ifndef TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_
|
|
|
|
|
#define TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_
|
2019-01-30 15:26:05 +01:00
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "api/units/timestamp.h"
|
|
|
|
|
#include "rtc_base/async_socket.h"
|
|
|
|
|
#include "rtc_base/critical_section.h"
|
|
|
|
|
#include "rtc_base/event.h"
|
|
|
|
|
#include "rtc_base/socket_server.h"
|
|
|
|
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
|
|
|
|
#include "system_wrappers/include/clock.h"
|
2020-01-07 17:52:24 +01:00
|
|
|
#include "test/network/network_emulation.h"
|
2019-01-30 15:26:05 +01:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
2020-01-07 17:52:24 +01:00
|
|
|
class FakeNetworkSocket;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
|
|
|
|
// FakeNetworkSocketServer must outlive any sockets it creates.
|
|
|
|
|
class FakeNetworkSocketServer : public rtc::SocketServer,
|
2020-01-07 17:52:24 +01:00
|
|
|
public sigslot::has_slots<> {
|
2019-01-30 15:26:05 +01:00
|
|
|
public:
|
2019-03-11 10:08:40 +01:00
|
|
|
FakeNetworkSocketServer(Clock* clock,
|
2019-03-28 12:11:09 +01:00
|
|
|
EndpointsContainer* endpoints_controller);
|
2019-01-30 15:26:05 +01:00
|
|
|
~FakeNetworkSocketServer() override;
|
|
|
|
|
|
2020-01-07 17:52:24 +01:00
|
|
|
EmulatedEndpointImpl* GetEndpointNode(const rtc::IPAddress& ip);
|
|
|
|
|
void Unregister(FakeNetworkSocket* socket);
|
2019-01-30 15:26:05 +01:00
|
|
|
void OnMessageQueueDestroyed();
|
|
|
|
|
|
|
|
|
|
// rtc::SocketFactory methods:
|
|
|
|
|
rtc::Socket* CreateSocket(int family, int type) override;
|
|
|
|
|
rtc::AsyncSocket* CreateAsyncSocket(int family, int type) override;
|
|
|
|
|
|
|
|
|
|
// rtc::SocketServer methods:
|
|
|
|
|
// Called by the network thread when this server is installed, kicking off the
|
|
|
|
|
// message handler loop.
|
2020-01-09 14:20:23 +01:00
|
|
|
void SetMessageQueue(rtc::Thread* msg_queue) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
bool Wait(int cms, bool process_io) override;
|
|
|
|
|
void WakeUp() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Timestamp Now() const;
|
|
|
|
|
|
|
|
|
|
Clock* const clock_;
|
2019-03-28 12:11:09 +01:00
|
|
|
const EndpointsContainer* endpoints_container_;
|
2019-01-30 15:26:05 +01:00
|
|
|
rtc::Event wakeup_;
|
2020-01-09 14:20:23 +01:00
|
|
|
rtc::Thread* msg_queue_;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
|
|
|
|
rtc::CriticalSection lock_;
|
2020-01-07 17:52:24 +01:00
|
|
|
std::vector<FakeNetworkSocket*> sockets_ RTC_GUARDED_BY(lock_);
|
2019-01-30 15:26:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2019-07-05 10:48:17 +02:00
|
|
|
#endif // TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_
|