UI: Add timeout parameter to RemoteTextThread

Allows specifying a timeout for the operation.
This commit is contained in:
jp9000 2018-11-23 18:14:57 -08:00
parent 4ba48484ae
commit 44834bbf04
2 changed files with 20 additions and 4 deletions

View File

@ -71,6 +71,10 @@ void RemoteTextThread::run()
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA,
&str);
if (timeoutSec)
curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT,
timeoutSec);
#if LIBCURL_VERSION_NUM >= 0x072400
// A lot of servers don't yet support ALPN
curl_easy_setopt(curl.get(), CURLOPT_SSL_ENABLE_ALPN, 0);
@ -118,7 +122,8 @@ bool GetRemoteFile(
const char *contentType,
const char *postData,
std::vector<std::string> extraHeaders,
std::string *signature)
std::string *signature,
int timeoutSec)
{
vector<string> header_in_list;
char error_in[CURL_ERROR_SIZE];
@ -166,6 +171,10 @@ bool GetRemoteFile(
&header_in_list);
}
if (timeoutSec)
curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT,
timeoutSec);
#if LIBCURL_VERSION_NUM >= 0x072400
// A lot of servers don't yet support ALPN
curl_easy_setopt(curl.get(), CURLOPT_SSL_ENABLE_ALPN, 0);

View File

@ -28,6 +28,8 @@ class RemoteTextThread : public QThread {
std::string contentType;
std::string postData;
int timeoutSec = 0;
void run() override;
signals:
@ -37,8 +39,12 @@ public:
inline RemoteTextThread(
std::string url_,
std::string contentType_ = std::string(),
std::string postData_ = std::string())
: url(url_), contentType(contentType_), postData(postData_)
std::string postData_ = std::string(),
int timeoutSec_ = 0)
: url (url_),
contentType (contentType_),
postData (postData_),
timeoutSec (timeoutSec_)
{}
};
@ -50,4 +56,5 @@ bool GetRemoteFile(
const char *contentType = nullptr,
const char *postData = nullptr,
std::vector<std::string> extraHeaders = std::vector<std::string>(),
std::string *signature = nullptr);
std::string *signature = nullptr,
int timeoutSec = 0);