diff --git a/cocos/network/CCDownloader.cpp b/cocos/network/CCDownloader.cpp index e47894c375..cb693aefbd 100644 --- a/cocos/network/CCDownloader.cpp +++ b/cocos/network/CCDownloader.cpp @@ -197,18 +197,18 @@ void Downloader::downloadToBuffer(const std::string& srcUrl, const std::string& CC_ASSERT(_downloaderImpl && "Cannot instanciate more than one instance of DownloaderImpl"); - DownloadUnit unit; - unit.srcUrl = srcUrl; - unit.customId = customId; - unit.fp = buffer; - unit.downloaded = 0; - unit.totalToDownload = 0; - StreamData streamBuffer; streamBuffer.buffer = buffer; streamBuffer.total = size; streamBuffer.offset = 0; + DownloadUnit unit; + unit.srcUrl = srcUrl; + unit.customId = customId; + unit.fp = &streamBuffer; + unit.downloaded = 0; + unit.totalToDownload = 0; + int res = _downloaderImpl->performDownload(&unit, std::bind(&Downloader::bufferWriteFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), std::bind(&Downloader::downloadProgressFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3) diff --git a/cocos/network/CCDownloaderImpl.cpp b/cocos/network/CCDownloaderImpl.cpp index 2616253d99..dad831d186 100644 --- a/cocos/network/CCDownloaderImpl.cpp +++ b/cocos/network/CCDownloaderImpl.cpp @@ -48,7 +48,10 @@ static size_t _fileWriteFunc(void *ptr, size_t size, size_t nmemb, void* userdat int ret = this_->getWriterCallback()(ptr, size, nmemb, unit); return ret; } - +static size_t _fileWriteFuncForAdapter(void *ptr, size_t size, size_t nmemb, void* userdata) +{ + return nmemb; +} static int _downloadProgressFunc(void* userdata, double totalToDownload, double nowDownloaded, double totalToUpLoad, double nowUpLoaded) { DownloadUnit *downloadUnit = (DownloadUnit*)userdata; @@ -284,7 +287,8 @@ int DownloaderImpl::getHeader(const std::string& url, HeaderInfo* headerInfo) curl_easy_setopt(curlHandle, CURLOPT_HEADER, 1); curl_easy_setopt(curlHandle, CURLOPT_NOBODY, 1); curl_easy_setopt(curlHandle, CURLOPT_NOSIGNAL, 1); - + // in win32 platform, if not set the writeFunction, it will return CURLE_WRITE_ERROR + curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, _fileWriteFuncForAdapter); if ((_lastErrCode=curl_easy_perform(curlHandle)) == CURLE_OK) { char *effectiveUrl;