#ifndef SERVER_H #define SERVER_H #include "handle.h" #include "jsondata.h" #include "zapi.h" #include "communicate.hpp" #include #include #include constexpr size_t g_BuffSize = 1024 * 10; struct ClientCache { std::array tmp_buf_{}; CMutBuffer buffer_{}; }; class Server { public: Server(asio::io_context& io_context, short port); void start(); void stop(); public: void set_worker(std::shared_ptr worker, std::shared_ptr json); 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); 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_{}; }; #endif