From 0d58a0bfe2f75c4ea354d0ea4bfa64514dca47ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 13 Jun 2017 19:17:11 +0200 Subject: [PATCH] HttpRequest: Add support for custom timeouts --- Source/Core/Common/HttpRequest.cpp | 8 ++++---- Source/Core/Common/HttpRequest.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/HttpRequest.cpp b/Source/Core/Common/HttpRequest.cpp index 5c83521972..b87ce4fb98 100644 --- a/Source/Core/Common/HttpRequest.cpp +++ b/Source/Core/Common/HttpRequest.cpp @@ -22,7 +22,7 @@ public: POST, }; - Impl(); + Impl(int timeout_ms); bool IsValid() const; Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload, @@ -32,7 +32,7 @@ private: std::unique_ptr m_curl{curl_easy_init(), curl_easy_cleanup}; }; -HttpRequest::HttpRequest() : m_impl(std::make_unique()) +HttpRequest::HttpRequest(int timeout_ms) : m_impl(std::make_unique(timeout_ms)) { } @@ -61,7 +61,7 @@ HttpRequest::Response HttpRequest::Post(const std::string& url, const std::strin reinterpret_cast(payload.data()), payload.size()); } -HttpRequest::Impl::Impl() +HttpRequest::Impl::Impl(int timeout_ms) { if (!m_curl) return; @@ -69,7 +69,7 @@ HttpRequest::Impl::Impl() // libcurl may not have been built with async DNS support, so we disable // signal handlers to avoid a possible and likely crash if a resolve times out. curl_easy_setopt(m_curl.get(), CURLOPT_NOSIGNAL, true); - curl_easy_setopt(m_curl.get(), CURLOPT_TIMEOUT, 3); + curl_easy_setopt(m_curl.get(), CURLOPT_TIMEOUT_MS, timeout_ms); #ifdef _WIN32 // ALPN support is enabled by default but requires Windows >= 8.1. curl_easy_setopt(m_curl.get(), CURLOPT_SSL_ENABLE_ALPN, false); diff --git a/Source/Core/Common/HttpRequest.h b/Source/Core/Common/HttpRequest.h index 0a1a86da82..4a1d7730d0 100644 --- a/Source/Core/Common/HttpRequest.h +++ b/Source/Core/Common/HttpRequest.h @@ -17,7 +17,7 @@ namespace Common class HttpRequest final { public: - HttpRequest(); + HttpRequest(int timeout_ms = 3000); ~HttpRequest(); bool IsValid() const;