This is an automated email from the ASF dual-hosted git repository. chhsiao pushed a commit to branch 1.4.x in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 6702196ae2c5d14180248c43c29bb6157478c174 Author: Chun-Hung Hsiao <chhs...@apache.org> AuthorDate: Wed Mar 28 22:47:46 2018 -0700 Added the `stall_timeout` parameter to `net::download()`. When the `stall_timeout` is given, the download would be aborted if the download speed keeps below 1 byte per second during the timeout. Review: https://reviews.apache.org/r/65855/ --- 3rdparty/stout/include/stout/net.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/3rdparty/stout/include/stout/net.hpp b/3rdparty/stout/include/stout/net.hpp index 7b6557d..9d99a6b 100644 --- a/3rdparty/stout/include/stout/net.hpp +++ b/3rdparty/stout/include/stout/net.hpp @@ -48,6 +48,7 @@ #include <string> #include <stout/bytes.hpp> +#include <stout/duration.hpp> #include <stout/error.hpp> #include <stout/ip.hpp> #include <stout/option.hpp> @@ -135,8 +136,12 @@ inline Try<Bytes> contentLength(const std::string& url) // Returns the HTTP response code resulting from attempting to // download the specified HTTP or FTP URL into a file at the specified -// path. -inline Try<int> download(const std::string& url, const std::string& path) +// path. The `stall_timeout` parameter controls how long the download +// waits before aborting when the download speed keeps below 1 byte/sec. +inline Try<int> download( + const std::string& url, + const std::string& path, + const Option<Duration>& stall_timeout = None()) { initialize(); @@ -175,6 +180,16 @@ inline Try<int> download(const std::string& url, const std::string& path) } curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); + if (stall_timeout.isSome()) { + // Set the options to abort the download if the speed keeps below + // 1 byte/sec during the timeout. See: + // https://curl.haxx.se/libcurl/c/CURLOPT_LOW_SPEED_LIMIT.html + // https://curl.haxx.se/libcurl/c/CURLOPT_LOW_SPEED_TIME.html + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt( + curl, CURLOPT_LOW_SPEED_TIME, static_cast<long>(stall_timeout->secs())); + } + CURLcode curlErrorCode = curl_easy_perform(curl); if (curlErrorCode != 0) { curl_easy_cleanup(curl);