mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 21:39:52 +00:00
Fix re-entrancy issue in Downloader
This commit is contained in:
parent
3bc2aaf7ca
commit
71cb766393
@ -582,7 +582,7 @@ std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, cons
|
||||
std::shared_ptr<Download> dl(new Download(RequestMethod::GET, url, "", "", outfile));
|
||||
if (acceptMime)
|
||||
dl->SetAccept(acceptMime);
|
||||
downloads_.push_back(dl);
|
||||
newDownloads_.push_back(dl);
|
||||
dl->Start();
|
||||
return dl;
|
||||
}
|
||||
@ -596,7 +596,7 @@ std::shared_ptr<Download> Downloader::StartDownloadWithCallback(
|
||||
if (acceptMime)
|
||||
dl->SetAccept(acceptMime);
|
||||
dl->SetCallback(callback);
|
||||
downloads_.push_back(dl);
|
||||
newDownloads_.push_back(dl);
|
||||
dl->Start();
|
||||
return dl;
|
||||
}
|
||||
@ -608,15 +608,20 @@ std::shared_ptr<Download> Downloader::AsyncPostWithCallback(
|
||||
std::string postMime = "application/x-www-form-urlencoded";
|
||||
std::shared_ptr<Download> dl(new Download(RequestMethod::POST, url, postData, postMime, Path()));
|
||||
dl->SetCallback(callback);
|
||||
downloads_.push_back(dl);
|
||||
newDownloads_.push_back(dl);
|
||||
dl->Start();
|
||||
return dl;
|
||||
}
|
||||
|
||||
void Downloader::Update() {
|
||||
for (auto iter : newDownloads_) {
|
||||
downloads_.push_back(iter);
|
||||
}
|
||||
newDownloads_.clear();
|
||||
|
||||
restart:
|
||||
for (size_t i = 0; i < downloads_.size(); i++) {
|
||||
auto &dl = downloads_[i];
|
||||
auto dl = downloads_[i];
|
||||
if (dl->Done()) {
|
||||
dl->RunCallback();
|
||||
dl->Join();
|
||||
|
@ -214,6 +214,9 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Download>> downloads_;
|
||||
// These get copied to downloads_ in Update(). It's so that callbacks can add new downloads
|
||||
// while running.
|
||||
std::vector<std::shared_ptr<Download>> newDownloads_;
|
||||
};
|
||||
|
||||
} // http
|
||||
|
Loading…
Reference in New Issue
Block a user