37class CliServer :
public slick::socket::TCPServerBase<CliServer> {
38 using Server = slick::socket::TCPServerBase<CliServer>;
46 explicit CliServer(
const slick::socket::TCPServerConfig &config,
52 void add_endpoints(
const std::string &group,
const std::vector<CliEndpoint *> &endpoints);
55 void set_feeds(std::string feeds) { feeds_ = std::move(feeds); }
57 void set_version(std::string version) { version_ = std::move(version); }
65 void flush(std::chrono::milliseconds limit);
68 [[nodiscard]] uint16_t
listen_port() const noexcept {
return Server::port(); }
73 void onClientData(
int client_id,
const uint8_t *data,
size_t length);
78 static constexpr size_t MAX_WAITING = 64;
82 bool answered =
false;
89 std::vector<Answer> answers;
91 std::chrono::steady_clock::time_point deadline;
94 std::deque<CliRequestMessage> waiting;
101 void dispatch(
int client_id);
102 void on_reply(
size_t endpoint, uint64_t ticket,
CliStatus status, std::string_view text);
104 void finish(uint64_t ticket);
105 void send_reply(
int client_id, uint32_t request_id,
CliStatus status, std::string_view text);
106 [[nodiscard]] std::string list_targets()
const;
108 std::chrono::milliseconds reply_timeout_;
110 std::vector<CliEndpoint *> endpoints_;
112 std::map<std::string, std::vector<size_t>, std::less<>> targets_;
115 std::string version_;
118 ControlStreams streams_{
sizeof(CliRequestMessage)};
119 std::unordered_map<int, Client> clients_;
120 std::unordered_map<uint64_t, Pending> pending_;
121 uint64_t next_ticket_ = 1;
122 std::vector<uint8_t> reply_;
123 std::vector<uint64_t> expired_;
125 std::atomic<size_t> pending_count_{0};
void add_endpoints(const std::string &group, const std::vector< CliEndpoint * > &endpoints)
Routes group, and every /-prefix of each endpoint's name, to the endpoints.