diff options
author | Brad King <brad.king@kitware.com> | 2011-06-01 13:55:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2011-06-01 13:55:42 (GMT) |
commit | faa7ec6e185c535548814f7aafd16c13346b514f (patch) | |
tree | c8a6304e5914dd02f6a9de749f77127bbd80995e /Source/cmFileCommand.cxx | |
parent | 8af1eaf499cb539719fa1698ea3031a70a861728 (diff) | |
download | CMake-faa7ec6e185c535548814f7aafd16c13346b514f.zip CMake-faa7ec6e185c535548814f7aafd16c13346b514f.tar.gz CMake-faa7ec6e185c535548814f7aafd16c13346b514f.tar.bz2 |
Teach file(DOWNLOAD|UPLOAD) to timeout after inactivity
Add option INACTIVITY_TIMEOUT to terminate the operation if there is no
progress for more than a given amount of time.
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index d28de08..9a3de9b 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -2614,6 +2614,7 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) ++i; long timeout = 0; + long inactivity_timeout = 0; std::string verboseLog; std::string statusVar; std::string expectedMD5sum; @@ -2634,6 +2635,19 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) return false; } } + else if(*i == "INACTIVITY_TIMEOUT") + { + ++i; + if(i != args.end()) + { + inactivity_timeout = atol(i->c_str()); + } + else + { + this->SetError("DOWNLOAD missing time for INACTIVITY_TIMEOUT."); + return false; + } + } else if(*i == "LOG") { ++i; @@ -2770,6 +2784,13 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) check_curl_result(res, "DOWNLOAD cannot set timeout: "); } + if(inactivity_timeout > 0) + { + // Give up if there is no progress for a long time. + ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1); + ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, inactivity_timeout); + } + // Need the progress helper's scope to last through the duration of // the curl_easy_perform call... so this object is declared at function // scope intentionally, rather than inside the "if(showProgress)" @@ -2883,6 +2904,7 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) ++i; long timeout = 0; + long inactivity_timeout = 0; std::string logVar; std::string statusVar; bool showProgress = false; @@ -2902,6 +2924,19 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) return false; } } + else if(*i == "INACTIVITY_TIMEOUT") + { + ++i; + if(i != args.end()) + { + inactivity_timeout = atol(i->c_str()); + } + else + { + this->SetError("UPLOAD missing time for INACTIVITY_TIMEOUT."); + return false; + } + } else if(*i == "LOG") { ++i; @@ -3003,6 +3038,13 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) check_curl_result(res, "UPLOAD cannot set timeout: "); } + if(inactivity_timeout > 0) + { + // Give up if there is no progress for a long time. + ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1); + ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, inactivity_timeout); + } + // Need the progress helper's scope to last through the duration of // the curl_easy_perform call... so this object is declared at function // scope intentionally, rather than inside the "if(showProgress)" |