Skip to content
Snippets Groups Projects
Commit 94942671 authored by Andrew A. de Laix's avatar Andrew A. de Laix
Browse files

fix resume crash.

parent dcf4ddac
No related branches found
No related tags found
No related merge requests found
...@@ -57,6 +57,7 @@ class LLUpdateDownloader::Implementation: ...@@ -57,6 +57,7 @@ class LLUpdateDownloader::Implementation:
LLSD mDownloadData; LLSD mDownloadData;
llofstream mDownloadStream; llofstream mDownloadStream;
std::string mDownloadRecordPath; std::string mDownloadRecordPath;
curl_slist * mHeaderList;
void initializeCurlGet(std::string const & url, bool processHeader); void initializeCurlGet(std::string const & url, bool processHeader);
void resumeDownloading(size_t startByte); void resumeDownloading(size_t startByte);
...@@ -154,7 +155,8 @@ LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & ...@@ -154,7 +155,8 @@ LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client &
LLThread("LLUpdateDownloader"), LLThread("LLUpdateDownloader"),
mCancelled(false), mCancelled(false),
mClient(client), mClient(client),
mCurl(0) mCurl(0),
mHeaderList(0)
{ {
CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case. CURLcode code = curl_global_init(CURL_GLOBAL_ALL); // Just in case.
llverify(code == CURLE_OK); // TODO: real error handling here. llverify(code == CURLE_OK); // TODO: real error handling here.
...@@ -302,6 +304,11 @@ void LLUpdateDownloader::Implementation::run(void) ...@@ -302,6 +304,11 @@ void LLUpdateDownloader::Implementation::run(void)
LLFile::remove(mDownloadRecordPath); LLFile::remove(mDownloadRecordPath);
mClient.downloadError("curl error"); mClient.downloadError("curl error");
} }
if(mHeaderList) {
curl_slist_free_all(mHeaderList);
mHeaderList = 0;
}
} }
...@@ -330,17 +337,18 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u ...@@ -330,17 +337,18 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u
void LLUpdateDownloader::Implementation::resumeDownloading(size_t startByte) void LLUpdateDownloader::Implementation::resumeDownloading(size_t startByte)
{ {
LL_INFOS("UpdateDownload") << "resuming download from " << mDownloadData["url"].asString()
<< " at byte " << startByte << LL_ENDL;
initializeCurlGet(mDownloadData["url"].asString(), false); initializeCurlGet(mDownloadData["url"].asString(), false);
// The header 'Range: bytes n-' will request the bytes remaining in the // The header 'Range: bytes n-' will request the bytes remaining in the
// source begining with byte n and ending with the last byte. // source begining with byte n and ending with the last byte.
boost::format rangeHeaderFormat("Range: bytes=%u-"); boost::format rangeHeaderFormat("Range: bytes=%u-");
rangeHeaderFormat % startByte; rangeHeaderFormat % startByte;
curl_slist * headerList = 0; mHeaderList = curl_slist_append(mHeaderList, rangeHeaderFormat.str().c_str());
headerList = curl_slist_append(headerList, rangeHeaderFormat.str().c_str()); if(mHeaderList == 0) throw DownloadError("cannot add Range header");
if(headerList == 0) throw DownloadError("cannot add Range header"); throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, mHeaderList));
throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, headerList));
curl_slist_free_all(headerList);
mDownloadStream.open(mDownloadData["path"].asString(), mDownloadStream.open(mDownloadData["path"].asString(),
std::ios_base::out | std::ios_base::binary | std::ios_base::app); std::ios_base::out | std::ios_base::binary | std::ios_base::app);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment