/** Callback function from curl: inform about progress. It makes sure that * the value reported by getProgress () is <1 while the download is still * in progress. * \param clientp * \param download_total Total size of data to download. * \param download_now How much has been downloaded so far. * \param upload_total Total amount of upload. * \param upload_now How muc has been uploaded so far. */ int HTTPRequest::progressDownload(void *clientp, double download_total, double download_now, double upload_total, double upload_now) { HTTPRequest *request = (HTTPRequest *)clientp; RequestManager* request_manager = RequestManager::get(); // Check if we are asked to abort the download. If so, signal this // back to libcurl by returning a non-zero status. if ((request_manager->getAbort() || request->isCancelled()) && request->isAbortable() ) { // Indicates to abort the current download, which means that this // thread will go back to the mainloop and handle the next request. return 1; } float f; if (download_now < download_total) { f = (float)download_now / (float)download_total; // In case of floating point rouding errors make sure that // 1.0 is only reached when downloadFileInternal is finished if (f >= 1.0f) f = 0.99f; } else { // Don't set progress to 1.0f; this is done in afterOperation() // after checking curls return code! f = (download_total == 0) ? 0 : 0.99f; } request->setProgress(f); return 0; } // progressDownload