Fix issue that __JSDownloaderDelegator::onError get called twice

This commit is contained in:
pandamicro 2015-06-04 15:03:20 +08:00
parent 9c23126d9e
commit 83f7f30c1c
2 changed files with 15 additions and 11 deletions

View File

@ -951,11 +951,7 @@ void __JSDownloaderDelegator::startDownload()
cocos2d::extension::Downloader::HeaderInfo info = _downloader->getHeader(_url);
long contentSize = info.contentSize;
if (contentSize == -1 || info.responseCode >= 400) {
cocos2d::extension::Downloader::Error err;
onError(err);
}
else {
if (contentSize > 0 && info.responseCode < 400) {
_size = contentSize / sizeof(unsigned char);
_buffer = (unsigned char*)malloc(contentSize);
_downloader->downloadToBufferSync(_url, _buffer, _size);

View File

@ -296,16 +296,24 @@ Downloader::HeaderInfo Downloader::prepareHeader(const std::string &srcUrl, void
curl_easy_getinfo(header, CURLINFO_CONTENT_TYPE, &contentType);
curl_easy_getinfo(header, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &info.contentSize);
curl_easy_getinfo(header, CURLINFO_RESPONSE_CODE, &info.responseCode);
info.url = url;
info.contentType = contentType;
info.valid = true;
if (_onHeader)
if (contentType == nullptr || info.contentSize == -1 || info.responseCode >= 400)
{
_onHeader(srcUrl, info);
info.valid = false;
}
else
{
info.url = url;
info.contentType = contentType;
info.valid = true;
}
}
else
if (info.valid && _onHeader)
{
_onHeader(srcUrl, info);
}
else if (!info.valid)
{
info.contentSize = -1;
std::string msg = StringUtils::format("Can not get content size of file (%s) : Request header failed", srcUrl.c_str());