lib/curl/Easy: use pass std::chrono::duration to SetTimeout()

This commit is contained in:
Max Kellermann 2024-07-10 14:20:52 +02:00 committed by Max Kellermann
parent 7c21d57953
commit 13576b8a2e
3 changed files with 12 additions and 10 deletions

View File

@ -138,7 +138,7 @@ static const char *cacert;
static bool verify_peer, verify_host;
/** Connection settings */
static long connect_timeout;
static std::chrono::duration<long> 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<long>(timeout);
constexpr std::chrono::seconds default_connection_timeout{10};
connect_timeout = std::chrono::duration_cast<std::chrono::duration<long>>(
block.GetDuration("connect_timeout",
std::chrono::seconds{1},
default_connection_timeout));
verbose = block.GetBlockValue("verbose",verbose);

View File

@ -8,6 +8,7 @@
#include <curl/curl.h>
#include <chrono>
#include <cstddef>
#include <span>
#include <stdexcept>
@ -139,12 +140,12 @@ public:
SetOption(CURLOPT_PROXY_SSL_VERIFYPEER, value);
}
void SetConnectTimeout(long timeout) {
SetOption(CURLOPT_CONNECTTIMEOUT, timeout);
void SetConnectTimeout(std::chrono::duration<long> timeout) {
SetOption(CURLOPT_CONNECTTIMEOUT, timeout.count());
}
void SetTimeout(long timeout) {
SetOption(CURLOPT_TIMEOUT, timeout);
void SetTimeout(std::chrono::duration<long> timeout) {
SetOption(CURLOPT_TIMEOUT, timeout.count());
}
void SetHeaderFunction(size_t (*function)(char *buffer, size_t size,

View File

@ -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);
}