From 0dd996c6a32ab7cd524081cff88f6e95efb5b4b5 Mon Sep 17 00:00:00 2001 From: luddens Date: Thu, 24 Oct 2019 17:40:42 +0200 Subject: [PATCH 1/3] add try catch around aria2 first commands --- src/downloader.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/downloader.cpp b/src/downloader.cpp index fa54e2e17..393810d2a 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() { From 9850be72677d8341b414f52aab31d9737ebfb6bf Mon Sep 17 00:00:00 2001 From: luddens Date: Fri, 25 Oct 2019 12:12:16 +0200 Subject: [PATCH 2/3] add Curl error message --- src/aria2.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/aria2.cpp b/src/aria2.cpp index 0cef601b7..420797aa8 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -80,16 +80,27 @@ Aria2::Aria2(): callCmd.push_back("--file-allocation=none"); 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) { From 20a2c78733cb69fba9dfa9b7addaff135008c6d3 Mon Sep 17 00:00:00 2001 From: luddens Date: Fri, 1 Nov 2019 11:04:23 +0200 Subject: [PATCH 3/3] add get aria2 launch cmd method --- include/downloader.h | 1 + src/aria2.cpp | 3 +++ src/aria2.h | 2 ++ src/downloader.cpp | 5 +++++ 4 files changed, 11 insertions(+) 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 420797aa8..07dfbdb03 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -78,6 +78,9 @@ 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]; 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 393810d2a..580445343 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -163,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) {