Issue #9061: Fix no success notification for empty download queue issue

This commit is contained in:
pandamicro 2014-11-10 16:51:41 +08:00
parent ead867559c
commit e167f0889b
1 changed files with 30 additions and 31 deletions

View File

@ -471,46 +471,45 @@ void Downloader::batchDownloadAsync(const DownloadUnits &units, const std::strin
void Downloader::batchDownloadSync(const DownloadUnits &units, const std::string &batchId/* = ""*/) void Downloader::batchDownloadSync(const DownloadUnits &units, const std::string &batchId/* = ""*/)
{ {
if (units.size() == 0)
{
return;
}
// Make sure downloader won't be released // Make sure downloader won't be released
std::weak_ptr<Downloader> ptr = shared_from_this(); std::weak_ptr<Downloader> ptr = shared_from_this();
// Test server download resuming support with the first unit if (units.size() != 0)
_supportResuming = false;
CURL *header = curl_easy_init();
// Make a resume request
curl_easy_setopt(header, CURLOPT_RESUME_FROM_LARGE, 0);
if (prepareHeader(header, units.begin()->second.srcUrl))
{ {
long responseCode; // Test server download resuming support with the first unit
curl_easy_getinfo(header, CURLINFO_RESPONSE_CODE, &responseCode); _supportResuming = false;
if (responseCode == HTTP_CODE_SUPPORT_RESUME) CURL *header = curl_easy_init();
// Make a resume request
curl_easy_setopt(header, CURLOPT_RESUME_FROM_LARGE, 0);
if (prepareHeader(header, units.begin()->second.srcUrl))
{ {
_supportResuming = true; long responseCode;
curl_easy_getinfo(header, CURLINFO_RESPONSE_CODE, &responseCode);
if (responseCode == HTTP_CODE_SUPPORT_RESUME)
{
_supportResuming = true;
}
} }
} curl_easy_cleanup(header);
curl_easy_cleanup(header);
int count = 0;
int count = 0; DownloadUnits group;
DownloadUnits group; for (auto it = units.cbegin(); it != units.cend(); ++it, ++count)
for (auto it = units.cbegin(); it != units.cend(); ++it, ++count) {
{ if (count == FOPEN_MAX)
if (count == FOPEN_MAX) {
groupBatchDownload(group);
group.clear();
count = 0;
}
const std::string &key = it->first;
const DownloadUnit &unit = it->second;
group.emplace(key, unit);
}
if (group.size() > 0)
{ {
groupBatchDownload(group); groupBatchDownload(group);
group.clear();
count = 0;
} }
const std::string &key = it->first;
const DownloadUnit &unit = it->second;
group.emplace(key, unit);
}
if (group.size() > 0)
{
groupBatchDownload(group);
} }
Director::getInstance()->getScheduler()->performFunctionInCocosThread([ptr, batchId]{ Director::getInstance()->getScheduler()->performFunctionInCocosThread([ptr, batchId]{