fix:修正一个连续下载时,文件之间间隔停顿的问题。
This commit is contained in:
parent
1677765111
commit
6cff24fd13
@ -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<std::mutex> 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<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user