From 6cff24fd139db5f641e9c29e13ece8b06f9b2761 Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 7 Apr 2025 11:31:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=AD=A3=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E8=BF=9E=E7=BB=AD=E4=B8=8B=E8=BD=BD=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B9=8B=E9=97=B4=E9=97=B4=E9=9A=94=E5=81=9C?= =?UTF-8?q?=E9=A1=BF=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/client/client.cpp b/client/client.cpp index 55940f8..0bc3e74 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -67,6 +67,7 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str client_->async_recv(); hearts_ = std::thread([&]() { hearts(); }); std::thread thread([&]() { io_context_.run(); }); + th_down_active_ = std::thread([&]() { judget_down_active(); }); auto* bf = new CFrameBuffer(); bf->type_ = TYPE_GET_ID; @@ -423,9 +424,6 @@ void CClient::report_trans_ret(TransState state, const std::string& key) t = down_; downloading_ = false; will_receive_ = false; - if (th_down_active_.joinable()) { - th_down_active_.join(); - } } else { std::lock_guard lock(mutex_); if (up_.count(key)) { @@ -763,7 +761,6 @@ void CClient::handle_frame(CFrameBuffer* buf) case TYPE_TRANS_FILE: { if (!downloading_) { downloading_ = true; - th_down_active_ = std::thread([&]() { judget_down_active(); }); } if (will_receive_) { down_->file_.write(buf->data_, buf->len_); @@ -1003,10 +1000,15 @@ void CClient::judget_down_active() { std::shared_ptr buf = std::make_shared(); buf->type_ = TYPE_JUDGE_ACTIVE; - buf->tid_ = down_->cur_remote_id_; - while (downloading_ && th_run_) { - std::this_thread::sleep_for(std::chrono::milliseconds(2000)); - send_frame(buf.get()); + while (th_run_) { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + if (!downloading_) { + continue; + } + if (down_) { + buf->tid_ = down_->cur_remote_id_; + send_frame(buf.get()); + } } }