Set timeout for libcurl call

This commit is contained in:
WarmUpTill
2021-06-27 20:50:39 +02:00
committed by WarmUpTill
parent 8d02f63c36
commit 9dfbd266fc
2 changed files with 16 additions and 0 deletions

View File

@@ -32,6 +32,14 @@ static std::string getRemoteData(std::string &url)
f_curl_setopt(switcher->curl, CURLOPT_WRITEFUNCTION,
WriteCallback);
f_curl_setopt(switcher->curl, CURLOPT_WRITEDATA, &readBuffer);
// Set timeout to at least one second
int timeout = switcher->interval / 1000;
if (timeout == 0) {
timeout = 1;
}
f_curl_setopt(switcher->curl, CURLOPT_TIMEOUT, 1);
f_curl_perform(switcher->curl);
}
return readBuffer;

View File

@@ -167,6 +167,14 @@ static std::string getRemoteData(std::string &url)
f_curl_setopt(switcher->curl, CURLOPT_WRITEFUNCTION,
WriteCallback);
f_curl_setopt(switcher->curl, CURLOPT_WRITEDATA, &readBuffer);
// Set timeout to at least one second
int timeout = switcher->interval / 1000;
if (timeout == 0) {
timeout = 1;
}
f_curl_setopt(switcher->curl, CURLOPT_TIMEOUT, 1);
f_curl_perform(switcher->curl);
}
return readBuffer;