reload torrents asynchronously when starting client

This commit is contained in:
arvidn 2017-05-04 22:46:30 -04:00 committed by Arvid Norberg
parent 8c57d11778
commit d2d96d6649
1 changed files with 34 additions and 37 deletions

View File

@ -1277,7 +1277,10 @@ MAGNETURL is a magnet link
else add_torrent(ses, i.to_string());
}
std::thread resume_data_loader([&ses]
{
// load resume files
error_code ec;
std::string const resume_dir = path_append(save_path, ".resume");
std::vector<std::string> ents = list_dir(resume_dir
, [](lt::string_view p) { return p.size() > 7 && p.substr(p.size() - 7) == ".resume"; }, ec);
@ -1288,7 +1291,6 @@ MAGNETURL is a magnet link
}
else
{
int idx = 0;
for (auto const& e : ents)
{
std::string const file = path_append(resume_dir, e);
@ -1314,16 +1316,9 @@ MAGNETURL is a magnet link
p.flags &= ~add_torrent_params::flag_need_save_resume;
ses.async_add_torrent(std::move(p));
++idx;
if ((idx % 32) == 0)
{
// regularly, pop and handle alerts, to avoid the alert queue from
// filling up with add_torrent_alerts
pop_alerts(view, ses_view, ses, events);
}
}
}
});
// main loop
std::vector<peer_info> peers;
@ -1938,6 +1933,8 @@ COLUMN OPTIONS
}
}
resume_data_loader.join();
ses.pause();
std::printf("saving resume data\n");