FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
datagram_source.hpp
Go to the documentation of this file.
1#pragma once
2// Datagram receive interface for multicast market data (ADR-0015, section 1). A source joins one
3// or more (interface, group, port, source?) subscriptions; the line index is the subscription's
4// position. A unicast "group" is a local address the datagrams are sent to (no join): for networks
5// without multicast. The net thread calls poll(handler), which delivers a batch and returns its
6// size. Payload spans are valid until poll returns; no backend allocates after open.
7//
8// Backends: KernelDatagramSource (kernel_datagram_source.hpp), XdpDatagramSource
9// (xdp_datagram_source.hpp), DpdkDatagramSource (dpdk_datagram_source.hpp). Descriptors and
10// statistics are backend-specific.
11#include "fastmm/core/time.hpp"
12
13#include <concepts>
14#include <cstddef>
15#include <cstdint>
16#include <span>
17
18namespace fastmm::net {
19
20struct RxMeta {
21 Cycles t0_cycles; // rdtscp after the batch left the kernel or the RX ring
22 std::int64_t t0_wall_ns; // CLOCK_REALTIME read with t0_cycles; sw_ts_ns -> T0 in one clock
23 std::int64_t sw_ts_ns; // kernel receive time (CLOCK_REALTIME), 0 when unavailable
24 std::int64_t hw_ts_ns; // raw NIC (PHC) time, 0 when unavailable; not CLOCK_REALTIME
25 std::uint32_t src_ip; // network byte order
26 std::uint32_t dst_ip; // network byte order: the subscription's group
27 std::uint16_t dst_port; // host byte order
28 std::uint8_t line; // subscription index (A/B)
29};
32 std::uint64_t datagrams = 0; // delivered to the handler
33 std::uint64_t bytes = 0; // payload bytes delivered
34 std::uint64_t truncated = 0; // larger than the receive buffer; dropped
35 std::uint64_t errors = 0; // failed receive calls other than EAGAIN
36 int last_error = 0; // errno of the last failed receive call
37};
39// A handler that accepts every datagram: the shape poll() is checked against.
41 void operator()(std::span<const std::byte>, const RxMeta&) const noexcept {}
42};
44template <class S>
45concept DatagramSource = requires(S& s, DatagramHandlerArchetype h) {
46 { s.poll(h) } noexcept -> std::same_as<std::size_t>;
47};
48
49} // namespace fastmm::net
Definition datagram_source.hpp:47
Definition reactor.hpp:37
A handler that accepts every datagram: the shape poll() is checked against.
Definition datagram_source.hpp:42
void operator()(std::span< const std::byte >, const RxMeta &) const noexcept
Definition datagram_source.hpp:43
Definition datagram_source.hpp:33
int last_error
errno of the last failed receive call
Definition datagram_source.hpp:38
std::uint64_t truncated
larger than the receive buffer; dropped
Definition datagram_source.hpp:36
std::uint64_t bytes
payload bytes delivered
Definition datagram_source.hpp:35
std::uint64_t datagrams
delivered to the handler
Definition datagram_source.hpp:34
std::uint64_t errors
failed receive calls other than EAGAIN
Definition datagram_source.hpp:37
Definition datagram_source.hpp:22
std::uint32_t dst_ip
network byte order: the subscription's group
Definition datagram_source.hpp:28
std::int64_t t0_wall_ns
CLOCK_REALTIME read with t0_cycles; sw_ts_ns -> T0 in one clock.
Definition datagram_source.hpp:24
std::uint16_t dst_port
host byte order
Definition datagram_source.hpp:29
std::uint32_t src_ip
network byte order
Definition datagram_source.hpp:27
std::int64_t sw_ts_ns
kernel receive time (CLOCK_REALTIME), 0 when unavailable
Definition datagram_source.hpp:25
std::uint8_t line
subscription index (A/B)
Definition datagram_source.hpp:30
Cycles t0_cycles
rdtscp after the batch left the kernel or the RX ring
Definition datagram_source.hpp:23
std::int64_t hw_ts_ns
raw NIC (PHC) time, 0 when unavailable; not CLOCK_REALTIME
Definition datagram_source.hpp:26
Time primitives.