webrtc_m130/test/network/fake_network_socket_server.h
Sebastian Jansson a406ee1ca2 Moving FakeNetworkSocket to fake_network_socket_server.h
This means that we avoid exposing FakeNetworkSocket and
moves related code closer together.

It's done in preparation for future work on simulated time testing.

Bug: webrtc:9883
Change-Id: Id6d1b0a6055f30da8e6646bd5347024fbd9c9dfd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/164537
Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30181}
2020-01-08 14:23:36 +00:00

70 lines
2.2 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.
*/
#ifndef TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_
#define TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_
#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/message_queue.h"
#include "rtc_base/socket_server.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "system_wrappers/include/clock.h"
#include "test/network/network_emulation.h"
namespace webrtc {
namespace test {
class FakeNetworkSocket;
// FakeNetworkSocketServer must outlive any sockets it creates.
class FakeNetworkSocketServer : public rtc::SocketServer,
public sigslot::has_slots<> {
public:
FakeNetworkSocketServer(Clock* clock,
EndpointsContainer* endpoints_controller);
~FakeNetworkSocketServer() override;
EmulatedEndpointImpl* GetEndpointNode(const rtc::IPAddress& ip);
void Unregister(FakeNetworkSocket* socket);
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.
void SetMessageQueue(rtc::MessageQueue* msg_queue) override;
bool Wait(int cms, bool process_io) override;
void WakeUp() override;
private:
Timestamp Now() const;
Clock* const clock_;
const EndpointsContainer* endpoints_container_;
rtc::Event wakeup_;
rtc::MessageQueue* msg_queue_;
rtc::CriticalSection lock_;
std::vector<FakeNetworkSocket*> sockets_ RTC_GUARDED_BY(lock_);
};
} // namespace test
} // namespace webrtc
#endif // TEST_NETWORK_FAKE_NETWORK_SOCKET_SERVER_H_