#pragma once #include #include #include #include #include #include using namespace ofen; struct ClientCache { std::shared_ptr socket_; CMutBuffer buffer_; std::array tmp_buf_; std::string task_; std::string time_; }; struct TaskList { std::string id_; std::string task_; std::string time_; }; class CTcpServer { public: CTcpServer(asio::io_context& io_context, const std::shared_ptr& logger); ~CTcpServer(); public: bool start(unsigned short port); void stop(); private: std::vector get_clients(); SimpleBuffer* get_client_list(); private: bool push_frame(CFrameBuffer* buf); void handle_frame(); void send_simple_buf(); private: void accept_client(); void th_client(std::shared_ptr socket, const std::string& client_key); private: bool th_run_{false}; asio::io_context& io_context_; asio::ip::tcp::acceptor acceptor_; std::shared_ptr logger_; std::map> client_map_; std::map client_threads_; std::mutex cli_mut_; std::queue cache_; std::queue scache_; std::mutex buf_mut_; std::mutex sbuf_mut_; std::shared_ptr handle_pool_; std::shared_ptr send_pool_; };