File downloader can now download multiple files

This commit is contained in:
Yousef Khadadeh 2025-10-09 12:03:03 +03:00
parent ed5708bbc6
commit dc834f84f8

View file

@ -52,15 +52,15 @@ void FileDownloader::download_thread_update() {
int stillRunning = 0; int stillRunning = 0;
mHandle = curl_multi_init(); mHandle = curl_multi_init();
add_new_handlers_to_multi();
do { for(;;) {
if(shutdownThread) if(shutdownThread)
break; break;
CURLMcode mc; CURLMcode mc;
int numfds; int numfds;
add_new_handlers_to_multi();
mc = curl_multi_perform(mHandle, &stillRunning); mc = curl_multi_perform(mHandle, &stillRunning);
for(;;) { for(;;) {
@ -88,13 +88,14 @@ void FileDownloader::download_thread_update() {
std::cout << "curl_multi failed" << std::endl; std::cout << "curl_multi failed" << std::endl;
break; break;
} }
} while(stillRunning); }
for(auto& download : currentDownloads) { for(auto& download : currentDownloads) {
download.data->status = DownloadData::Status::FAILURE; download.data->status = DownloadData::Status::FAILURE;
curl_multi_remove_handle(mHandle, download.eHandle); curl_multi_remove_handle(mHandle, download.eHandle);
curl_easy_cleanup(download.eHandle); curl_easy_cleanup(download.eHandle);
} }
currentDownloads.clear(); currentDownloads.clear();
curl_multi_cleanup(mHandle); curl_multi_cleanup(mHandle);
} }
@ -121,6 +122,7 @@ void FileDownloader::cleanup() {
shutdownThread = true; shutdownThread = true;
downloadThread->join(); downloadThread->join();
} }
downloadThread = nullptr;
curl_global_cleanup(); curl_global_cleanup();
} }