diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 5f56d6d01..e9a22794d 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -138,7 +138,7 @@ static const char *cacert; static bool verify_peer, verify_host; /** Connection settings */ -static long connect_timeout; +static std::chrono::duration connect_timeout; /** * CURLOPT_VERBOSE - verbose mode @@ -406,10 +406,11 @@ input_curl_init(EventLoop &event_loop, const ConfigBlock &block) verify_peer = block.GetBlockValue("verify_peer", default_verify); verify_host = block.GetBlockValue("verify_host", default_verify); - constexpr unsigned default_connection_timeout = 10; - unsigned timeout = block.GetBlockValue("connect_timeout", - default_connection_timeout); - connect_timeout = static_cast(timeout); + constexpr std::chrono::seconds default_connection_timeout{10}; + connect_timeout = std::chrono::duration_cast>( + block.GetDuration("connect_timeout", + std::chrono::seconds{1}, + default_connection_timeout)); verbose = block.GetBlockValue("verbose",verbose); diff --git a/src/lib/curl/Easy.hxx b/src/lib/curl/Easy.hxx index 29bf63eba..4b75afbb8 100644 --- a/src/lib/curl/Easy.hxx +++ b/src/lib/curl/Easy.hxx @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -139,12 +140,12 @@ public: SetOption(CURLOPT_PROXY_SSL_VERIFYPEER, value); } - void SetConnectTimeout(long timeout) { - SetOption(CURLOPT_CONNECTTIMEOUT, timeout); + void SetConnectTimeout(std::chrono::duration timeout) { + SetOption(CURLOPT_CONNECTTIMEOUT, timeout.count()); } - void SetTimeout(long timeout) { - SetOption(CURLOPT_TIMEOUT, timeout); + void SetTimeout(std::chrono::duration timeout) { + SetOption(CURLOPT_TIMEOUT, timeout.count()); } void SetHeaderFunction(size_t (*function)(char *buffer, size_t size, diff --git a/src/lib/curl/Setup.cxx b/src/lib/curl/Setup.cxx index b0f46adb3..01ba04e0c 100644 --- a/src/lib/curl/Setup.cxx +++ b/src/lib/curl/Setup.cxx @@ -16,7 +16,7 @@ Setup(CurlEasy &easy) #endif easy.SetNoProgress(); easy.SetNoSignal(); - easy.SetConnectTimeout(10); + easy.SetConnectTimeout(std::chrono::seconds{10}); easy.SetOption(CURLOPT_HTTPAUTH, (long) CURLAUTH_ANY); }