The simplistic usage of libcurl was shown in Chapter 2, Native Libraries. Now, we extend the code using the previously mentioned multithreading primitives to allow asynchronous downloads.
The clDownloadTask
class introduced here keeps track of the download process and invokes a callback when the process completes:
class clDownloadTask: public iTask { public:
The constructor accepts URL of the resource to download, a unique task identifier, a callback, and a pointer to the instance of the downer:
clDownloadTask( const std::string& URL, size_t TaskID, const clPtr<clDownloadCompleteCallback>& CB, clDownloader* Downloader );
We will focus on the Run()
, Progress()
, and InvokeCallback()
methods, as they form the main logic of this class:
virtual void Run() override; private: void Progress( double TotalToDownload, double NowDownloaded, double TotalToUpload, double NowUploaded ); void InvokeCallback...