summaryrefslogtreecommitdiffstats
path: root/net/DelaySocket.hpp
blob: 256433f87d488925c974e49b50165134d7a6bbc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <Socket.hpp>

#include <mutex>

/// Simulates network latency for local debugging.
///
/// We are lifecycle managed internally based on the physical /
/// delayFd lifecycle.
///
/// An instance of Delay must be created before using the
/// static members and must outlive all sockets.
class Delay final
{
public:
    Delay(std::size_t latencyMs);
    ~Delay();

    static int create(int delayMs, int physicalFd);
    static void dumpState(std::ostream &os);

private:
    static std::shared_ptr<TerminatingPoll> DelayPoll;
    static std::once_flag DelayPollOnceFlag;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */