#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_{}; FrameType cur_type_{TYPE_DEFAULT}; }; 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(); void get_client_list(CFrameBuffer** buf); private: void trans_data(CFrameBuffer* buf); bool check_double(CFrameBuffer* buf, std::shared_ptr& fcli, std::shared_ptr& tcli); private: void accept_client(); void th_client(std::shared_ptr socket, const std::string& client_key); /// @brief 不删除 buf /// @param socket /// @param buf /// @return bool send_frame(std::shared_ptr socket, CFrameBuffer* buf); 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::mutex buf_mut_; std::string server_ip_; };