Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::net::TrafficCounters Class Reference

Counts the datagrams exchanged with one peer, by direction and packet type. More...

#include <aegis2d/net/traffic.hpp>

Public Types

using Clock = std::chrono::steady_clock
 Clock of the one-second windows.
 

Public Member Functions

void record (Direction direction, PacketType type, std::size_t bytes, Clock::time_point now) noexcept
 Records a datagram whose header was read.
 
void record (Direction direction, std::size_t bytes, Clock::time_point now) noexcept
 Records a datagram of unknown type, such as one too short for a header.
 
TrafficCount total (Direction direction) const noexcept
 Every datagram of a direction since the counters were created.
 
TrafficCount total (Direction direction, PacketType type) const noexcept
 The datagrams of one type and direction since the counters were created.
 
TrafficCount last_second (Direction direction, Clock::time_point now) const noexcept
 Every datagram of a direction during the last whole second.
 
TrafficCount last_second (Direction direction, PacketType type, Clock::time_point now) const noexcept
 The datagrams of one type and direction during the last whole second.
 

Detailed Description

Counts the datagrams exchanged with one peer, by direction and packet type.

One per peer, like ReliableChannel: record() each datagram sent or received. total() counts since the counters were created; last_second() counts the last whole second, from second boundaries counted from the first record(), so it reads 0 once a second went by without traffic. A datagram whose type is unknown (dropped before its header could be read) is counted in the direction totals only.

Not thread-safe: use it from the thread that sends and receives.

Member Typedef Documentation

◆ Clock

using aegis2d::net::TrafficCounters::Clock = std::chrono::steady_clock

Clock of the one-second windows.

Member Function Documentation

◆ last_second() [1/2]

TrafficCount aegis2d::net::TrafficCounters::last_second ( Direction  direction,
Clock::time_point  now 
) const
noexcept

Every datagram of a direction during the last whole second.

Parameters
directionSent or received.
nowCurrent time.
Returns
The count: datagrams and bytes per second.

◆ last_second() [2/2]

TrafficCount aegis2d::net::TrafficCounters::last_second ( Direction  direction,
PacketType  type,
Clock::time_point  now 
) const
noexcept

The datagrams of one type and direction during the last whole second.

Parameters
directionSent or received.
typePacket type.
nowCurrent time.
Returns
The count: datagrams and bytes per second.

◆ record() [1/2]

void aegis2d::net::TrafficCounters::record ( Direction  direction,
PacketType  type,
std::size_t  bytes,
Clock::time_point  now 
)
noexcept

Records a datagram whose header was read.

Parameters
directionSent or received.
typeType of the datagram.
bytesSize of the datagram, header included.
nowTime of the send or of the arrival.

◆ record() [2/2]

void aegis2d::net::TrafficCounters::record ( Direction  direction,
std::size_t  bytes,
Clock::time_point  now 
)
noexcept

Records a datagram of unknown type, such as one too short for a header.

Parameters
directionSent or received.
bytesSize of the datagram.
nowTime of the send or of the arrival.

◆ total() [1/2]

TrafficCount aegis2d::net::TrafficCounters::total ( Direction  direction) const
noexcept

Every datagram of a direction since the counters were created.

Parameters
directionSent or received.
Returns
The count, datagrams of unknown type included.

◆ total() [2/2]

TrafficCount aegis2d::net::TrafficCounters::total ( Direction  direction,
PacketType  type 
) const
noexcept

The datagrams of one type and direction since the counters were created.

Parameters
directionSent or received.
typePacket type.
Returns
The count.

The documentation for this class was generated from the following file: