UI: Join downloads on destruct.

This commit is contained in:
Unknown W. Brackets 2019-09-28 11:40:10 -07:00
parent 1307273dd7
commit 987448577f
2 changed files with 12 additions and 10 deletions

View File

@ -428,16 +428,16 @@ int Client::ReadResponseEntity(Buffer *readbuf, const std::vector<std::string> &
}
Download::Download(const std::string &url, const std::string &outfile)
: progress_(0.0f), url_(url), outfile_(outfile), resultCode_(0), completed_(false), failed_(false), cancelled_(false), hidden_(false) {
: url_(url), outfile_(outfile) {
}
Download::~Download() {
if (thread_.joinable())
thread_.join();
}
void Download::Start(std::shared_ptr<Download> self) {
std::thread th(std::bind(&Download::Do, this, self));
th.detach();
thread_ = std::thread(std::bind(&Download::Do, this, self));
}
void Download::SetFailed(int code) {
@ -577,6 +577,7 @@ void Downloader::CancelAll() {
for (size_t i = 0; i < downloads_.size(); i++) {
downloads_[i]->Cancel();
}
downloads_.clear();
}
} // http

View File

@ -142,16 +142,17 @@ private:
int PerformGET(const std::string &url);
std::string RedirectLocation(const std::string &baseUrl);
void SetFailed(int code);
float progress_;
float progress_ = 0.0f;
Buffer buffer_;
std::vector<std::string> responseHeaders_;
std::string url_;
std::string outfile_;
int resultCode_;
bool completed_;
bool failed_;
bool cancelled_;
bool hidden_;
std::thread thread_;
int resultCode_ = 0;
bool completed_ = false;
bool failed_ = false;
bool cancelled_ = false;
bool hidden_ = false;
std::function<void(Download &)> callback_;
};