Skip to content

Commit

Permalink
UI: Join downloads on destruct.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Sep 28, 2019
1 parent 1307273 commit 9874485
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions ext/native/net/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -577,6 +577,7 @@ void Downloader::CancelAll() {
for (size_t i = 0; i < downloads_.size(); i++) {
downloads_[i]->Cancel();
}
downloads_.clear();
}

} // http
13 changes: 7 additions & 6 deletions ext/native/net/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ class Download {
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_;
};

Expand Down

0 comments on commit 9874485

Please sign in to comment.