diff --git a/include/downloader.h b/include/downloader.h index b60e48136..35d44f62c 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -97,6 +97,7 @@ class Downloader size_t getNbDownload() { return m_knownDownloads.size(); } std::vector getDownloadIds(); + const std::string &getAria2LaunchCmd(); private: std::map> m_knownDownloads; diff --git a/src/aria2.cpp b/src/aria2.cpp index 0cef601b7..07dfbdb03 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -78,18 +78,32 @@ Aria2::Aria2(): callCmd.push_back("--max-concurrent-downloads=42"); callCmd.push_back("--rpc-max-request-size=6M"); callCmd.push_back("--file-allocation=none"); + for (auto &cmd : callCmd) { + m_launchCmd.append(cmd).append(" "); + } mp_aria = Subprocess::run(callCmd); mp_curl = curl_easy_init(); + char errbuf[CURL_ERROR_SIZE]; curl_easy_setopt(mp_curl, CURLOPT_URL, "http://localhost/rpc"); curl_easy_setopt(mp_curl, CURLOPT_PORT, m_port); curl_easy_setopt(mp_curl, CURLOPT_POST, 1L); + curl_easy_setopt(mp_curl, CURLOPT_ERRORBUFFER, errbuf); int watchdog = 50; while(--watchdog) { sleep(10); + errbuf[0] = 0; auto res = curl_easy_perform(mp_curl); if (res == CURLE_OK) { break; + } else if (watchdog == 1) { + std::cerr <<" curl_easy_perform() failed." << std::endl; + fprintf(stderr, "\nlibcurl: (%d) ", res); + if (errbuf[0] != 0) { + std::cerr << errbuf << std::endl; + } else { + std::cerr << curl_easy_strerror(res) << std::endl; + } } } if (!watchdog) { diff --git a/src/aria2.h b/src/aria2.h index 898904a5d..6d7262479 100644 --- a/src/aria2.h +++ b/src/aria2.h @@ -26,6 +26,7 @@ class Aria2 std::string m_downloadDir; CURL* mp_curl; pthread_mutex_t m_lock; + std::string m_launchCmd; std::string doRequest(const MethodCall& methodCall); @@ -43,6 +44,7 @@ class Aria2 void pause(const std::string& gid); void unpause(const std::string& gid); void remove(const std::string& gid); + const std::string &getLaunchCmd() { return m_launchCmd; }; }; }; //end namespace kiwix diff --git a/src/downloader.cpp b/src/downloader.cpp index fa54e2e17..580445343 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -127,17 +127,24 @@ void Download::cancelDownload() Downloader::Downloader() : mp_aria(new Aria2()) { - for (auto gid : mp_aria->tellActive()) { - m_knownDownloads[gid] = std::unique_ptr(new Download(mp_aria, gid)); - m_knownDownloads[gid]->updateStatus(); + try { + for (auto gid : mp_aria->tellActive()) { + m_knownDownloads[gid] = std::unique_ptr(new Download(mp_aria, gid)); + m_knownDownloads[gid]->updateStatus(); + } + } catch (std::exception& e) { + std::cerr << "aria2 tellActive failed : " << e.what(); } - for (auto gid : mp_aria->tellWaiting()) { - m_knownDownloads[gid] = std::unique_ptr(new Download(mp_aria, gid)); - m_knownDownloads[gid]->updateStatus(); + try { + for (auto gid : mp_aria->tellWaiting()) { + m_knownDownloads[gid] = std::unique_ptr(new Download(mp_aria, gid)); + m_knownDownloads[gid]->updateStatus(); + } + } catch (std::exception& e) { + std::cerr << "aria2 tellWaiting failed : " << e.what(); } } - /* Destructor */ Downloader::~Downloader() { @@ -156,6 +163,11 @@ std::vector Downloader::getDownloadIds() { return ret; } +const std::string &Downloader::getAria2LaunchCmd() +{ + return mp_aria->getLaunchCmd(); +} + Download* Downloader::startDownload(const std::string& uri) { for (auto& p: m_knownDownloads) {