itch-mold-replay 1.0
Time-accurate NASDAQ TotalView-ITCH 5.0 replay over MoldUDP64
Loading...
Searching...
No Matches
feed_pool.h
Go to the documentation of this file.
1#pragma once
2#include "imr/mold/packet_builder.h"
3#include "imr/mold/retransmission/feed.h"
4#include "imr/mold/retransmission_buffer.h"
5#include <sys/eventfd.h>
6#include <vector>
7#include <thread>
8namespace imr::mold::retransmission
9{
10 /** Owns N (`num_feeds`) retransmission feeds.
11 *
12 * Each feed runs own event loop in dedicated thread.
13 * All feeds share a single eventfd used to signal shutdown (via `stop()`)
14 */
16 {
17 public:
18 /** Constructs and starts `num_feeds` retransmission feeds in their own threads.
19 *
20 * Each thread construct an instance of `imr::mold::retransmission::Feed` and then starts it immediately.
21 *
22 * @throws std::system_error if the shutdown eventfd fails to be created.
23 */
24 FeedPool(std::size_t num_feeds,
25 const Feed::Config& feed_cfg,
26 const PacketBuilder::Config& packet_builder_cfg,
27 std::span<const char> file,
28 const RetransmissionBuffer& retransmission_buffer);
29 /** Signals all feed threads to stop by writing to the shared shutdown_fd_.
30 *
31 * This is async so retransmission feeds meaning retransmission feeds might finish requests in their epoll set before
32 * receiving the shutdown signal
33 *
34 * @throws std::system_error if write() to shutdown_fd_ fails.
35 */
36 void stop() const;
37
38 private:
39 util::FileDescriptor shutdown_fd_{[] { return eventfd(0, EFD_CLOEXEC); }};
40 std::vector<std::jthread> feeds_;
41 // we have to store these as members otherwise have to copy them N times in constructor
42 // (if we pass reference from constructor then it can go out of scope before threads have finished using them)
43 const Feed::Config* feed_cfg_;
44 const PacketBuilder::Config* packet_builder_cfg_;
45 };
46}
Builds MoldUDP64 packets.
Definition packet_builder.h:24
Retransmission buffer of the last buffer_size messages.
Definition retransmission_buffer.h:15
Owns N (num_feeds) retransmission feeds.
Definition feed_pool.h:16
FeedPool(std::size_t num_feeds, const Feed::Config &feed_cfg, const PacketBuilder::Config &packet_builder_cfg, std::span< const char > file, const RetransmissionBuffer &retransmission_buffer)
Constructs and starts num_feeds retransmission feeds in their own threads.
void stop() const
Signals all feed threads to stop by writing to the shared shutdown_fd_.
MoldUDP64 retransmission server.
Definition feed.h:18
RAII file descriptor wrapper.
Definition file_descriptor.h:19
Definition feed.h:15
Definition file_descriptor.h:11
Definition packet_builder.h:30