Help! In Android, AssetsManager download very slow!


#1

@Minggo Zhang

hi Minggo, my project has implemented making a new thread to download a Assets file folder on the net.
in win32, the speed can reach almost 1000kb/s,
but in Android, the speed will drop down to 50kb/s,
i am very puzzle! Help!

Here is some codes below:

void AssetsManager::update()
{
// begin
pthread_create(&s_updateThread, NULL, updateAsync, NULL);

}

void* AssetsManager::updateAsync(void* data)
{
// here is 2.x update function

}

bool AssetsManager::downLoad()
{

CCAsyncMessage::sharedManager()->pushMessage(DownloadStart);

CCLog(“start download : s", _packageUrl.c_str());
s_lastTime = time(NULL);
// Download pacakge
CURLcode res;
curl_easy_setopt(_curl, CURLOPT_URL, _packageUrl.c_str());
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, downLoadPackage);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(_curl, CURLOPT_NOPROGRESS, false);
curl_easy_setopt(_curl, CURLOPT_PROGRESSFUNCTION, progressFunc);

double downloadedSize = CCUserDefault::sharedUserDefault()-\>getDoubleForKey(KEY\_OF\_DOWNLOADED\_SIZE);
if (downloadedSize != 0)
{
    s\_haveDownloadedSize = s\_downloadStartPoint = downloadedSize;
    char size\_char[64];
    sprintf(size\_char, "d-”, (unsigned long)downloadedSize);

curl_easy_setopt(_curl, CURLOPT_RANGE, size_char);
}

res = curl_easy_perform(_curl);
curl_easy_cleanup(_curl);
if (res != 0)
{
CCLog(“error when download package %d”, res);
fclose(fp);
CCUserDefault::sharedUserDefault()->setDoubleForKey(KEY_OF_DOWNLOADED_SIZE, s_haveDownloadedSize);
CCAsyncMessage::sharedManager()->pushMessage(DownloadError, res);
return false;
}
fclose(fp);

CCLog(“succeed download package”);
s_haveDownloadedSize = 0;
CCUserDefault::sharedUserDefault()->setDoubleForKey(KEY_OF_DOWNLOADED_SIZE, 0);
CCAsyncMessage::sharedManager()->pushMessage(DownloadEnd);
return true;
}