#ifndef SERVER_H #define SERVER_H #include #include #include #include "communicate.hpp" #include "jsondata.h" #include "zapi.h" struct ClientCache { std::array tmp_buf_{}; CMutBuffer buffer_; }; class Server { public: Server(asio::io_context& io_context, uint16_t port); ~Server(); public: void start(); void stop(); public: void set_worker(std::shared_ptr worker, std::shared_ptr json); void set_token(int32_t tokens); private: void do_accept(); void th_client(const std::shared_ptr& socket, const std::string& client_key); std::string post_data(const std::string& data); bool send_frame(const std::shared_ptr& socket, FrameData& data); void print_exception(const std::exception& e); private: asio::io_context& io_context_; asio::ip::tcp::acceptor acceptor_; std::shared_ptr worker_; std::shared_ptr json_; std::mutex ask_mutex_; std::mutex cli_mutex_; std::unordered_map clients_; std::map> client_map_; CMutBuffer buffer_; uint16_t port_; int32_t tokens_{}; int32_t use_tokens_{}; }; #endif