5#include <slick/queue.hpp>
6#include <slick/socket/tcp_server.h>
19#include <unordered_set>
43 using Server = slick::socket::TCPServerBase<PcapControlServer>;
47 PcapControlServer(std::string name,
const slick::socket::TCPServerConfig &config, std::string cli_name);
55 [[nodiscard]] uint16_t
listen_port() const noexcept {
return Server::port(); }
67 [[nodiscard]]
bool take_start() noexcept {
return start_requested_.exchange(
false, std::memory_order_acq_rel); }
79 void onClientData(
int client_id,
const uint8_t *data,
size_t length);
83 static constexpr uint32_t QUEUE_SLOTS = 1024;
87 uint16_t message_size;
91 void request_start() noexcept { start_requested_.store(
true, std::memory_order_release); }
94 bool serve_cli(
const cli::Command &command, std::string &out);
97 slick::queue<StatusSlot> outbox_{QUEUE_SLOTS};
98 std::atomic<bool> start_requested_{
false};
99 cli::CliEndpoint cli_;
102 uint64_t outbox_cursor_ = 0;
103 std::optional<StatusSlot> last_status_;
104 std::unordered_set<int> clients_;
105 ControlStreams streams_{
sizeof(StartMessage)};
Where the CLI server's commands reach a thread that owns some state (the main thread,...
cli::CliEndpoint & cli() noexcept
The feed's CLI endpoint, served on the server thread while it runs.
void publish_status(const FeedStatusMessage &status, std::string_view message)
Sends status to every client now connected, and to each one that connects before the next.
void serve_unstarted()
After start() failed, so no server thread exists: serves the CLI from the calling thread,...
void onClientDisconnected(int client_id)
bool take_start() noexcept
True once, after a client has sent START. Exchange thread.
uint16_t listen_port() const noexcept
The bound port; with a configured port of 0, the one the OS assigned.
void onClientConnected(int client_id, const std::string &client_address)
void onClientData(int client_id, const uint8_t *data, size_t length)
bool start()
False when the port could not be bound.
static constexpr size_t MAX_MESSAGE
How much of a status's message the CLI reports.
PcapControlServer(std::string name, const slick::socket::TCPServerConfig &config, std::string cli_name)
cli_name is the CLI endpoint's (cli::pcap_feed_path).