From 9dfbd266fc708c56f2707669a5c9cf32b468f07d Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 27 Jun 2021 20:50:39 +0200 Subject: [PATCH] Set timeout for libcurl call --- src/macro-condition-file.cpp | 8 ++++++++ src/switch-file.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/macro-condition-file.cpp b/src/macro-condition-file.cpp index 42b61396..ec3505a8 100644 --- a/src/macro-condition-file.cpp +++ b/src/macro-condition-file.cpp @@ -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; diff --git a/src/switch-file.cpp b/src/switch-file.cpp index 6aa66181..03d75078 100644 --- a/src/switch-file.cpp +++ b/src/switch-file.cpp @@ -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;