From 2cdd2d4f4f04c5f13ef7082406e8ef8e0eed79d0 Mon Sep 17 00:00:00 2001 From: cxh Date: Wed, 21 Jan 2026 15:00:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/tunnel_client.hpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/include/tunnel_client.hpp b/include/tunnel_client.hpp index 2ca6cd4..233f84c 100644 --- a/include/tunnel_client.hpp +++ b/include/tunnel_client.hpp @@ -1,28 +1,30 @@ #pragma once + #include +#include #include #include -#include +#include +#include -namespace websocketpp -{ -namespace client -{ -} -} // namespace websocketpp +// websocketpp 客户端类型 +using ws_client = websocketpp::client; class TunnelClient { public: TunnelClient(const std::string& vid, const std::string& server_ws_url, int local_http_port); + void start(); void stop(); private: void run_loop(); - // 新增:流式处理 & 安全发送 + // 处理 Server 的 JSON 请求(GET / POST / 大文件流) void handle_request_and_reply(const nlohmann::json& req); + + // 线程安全发送函数 void send_text_safe(const std::string& s); void send_binary_safe(const void* data, size_t len); @@ -34,7 +36,7 @@ class TunnelClient std::atomic running_{false}; std::thread th_; - // websocketpp 句柄 + // websocketpp + ws_client* client_ = nullptr; websocketpp::connection_hdl hdl_; - ws_client* client_ = nullptr; // 指向 run_loop 的 client };