#pragma once #include #include #include #include #include #include #include #include #include using namespace ofen; using high_c = std::chrono::time_point; struct ClientCache { std::shared_ptr socket_; CMutBuffer buffer_; std::array tmp_buf_{}; std::string task_; std::string uuid; std::string task_time_; std::string online_time_; uint64_t timestamp{}; high_c last_active_time_; FrameType cur_type_{TYPE_DEFAULT}; }; class TransmServer { public: explicit TransmServer(asio::io_context& io_context); ~TransmServer(); public: bool start(unsigned short port); void stop(); private: void get_client_list(CMessageInfo& msg_info); 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(const std::shared_ptr& socket, const std::string& client_key); bool send_frame(const std::shared_ptr& socket, CFrameBuffer* buf); void monitor_idle(); private: bool th_run_{false}; asio::io_context& io_context_; asio::ip::tcp::acceptor acceptor_; std::map> client_map_; std::map client_threads_; std::shared_mutex cli_mut_; std::thread th_monitor_idle_; std::string server_ip_; CThreadSleep sleep_; };