From 430ddb6b59ed9375bcb08aadd6385489c413dabc Mon Sep 17 00:00:00 2001 From: randomdan Date: Mon, 28 Feb 2011 11:14:54 +0000 Subject: Add support for a timeout, settable in ms, defaulting to 6000, for xslRows --- project2/curlHelper.cpp | 22 +++++++++++++++------- project2/curlHelper.h | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/project2/curlHelper.cpp b/project2/curlHelper.cpp index eb6bf74..742e4de 100644 --- a/project2/curlHelper.cpp +++ b/project2/curlHelper.cpp @@ -7,7 +7,8 @@ CurlHelper::CurlHelper(const xmlpp::Element * p) : proxy(p, "proxy", false), method(p, "username", false), userName(p, "username", false), - password(p, "password", false) + password(p, "password", false), + timeout(p, "timeout", false, Variable(6000)) { } @@ -21,17 +22,24 @@ CurlHelper::newCurl() const CurlHandle::Ptr c = new CurlHandle(); c->setopt(CURLOPT_FOLLOWLOCATION, 1); c->setopt(CURLOPT_ENCODING, "deflate, gzip"); - setopt(c, CURLOPT_URL, url()); - setopt(c, CURLOPT_USERAGENT, userAgent()); - setopt(c, CURLOPT_PROXY, proxy()); - setopt(c, CURLOPT_COOKIEFILE, cookieJar()); - setopt(c, CURLOPT_COOKIEJAR, cookieJar()); + setopt_s(c, CURLOPT_URL, url()); + setopt_s(c, CURLOPT_USERAGENT, userAgent()); + setopt_s(c, CURLOPT_PROXY, proxy()); + setopt_s(c, CURLOPT_COOKIEFILE, cookieJar()); + setopt_s(c, CURLOPT_COOKIEJAR, cookieJar()); + setopt_l(c, CURLOPT_TIMEOUT_MS, timeout()); return c; } void -CurlHelper::setopt(CurlHandle::Ptr c, CURLoption o, const char * v) +CurlHelper::setopt_s(CurlHandle::Ptr c, CURLoption o, const char * v) { c->setopt(o, v); } +void +CurlHelper::setopt_l(CurlHandle::Ptr c, CURLoption o, int64_t v) +{ + c->setopt(o, (long)v); +} + diff --git a/project2/curlHelper.h b/project2/curlHelper.h index fd4d265..af26a50 100644 --- a/project2/curlHelper.h +++ b/project2/curlHelper.h @@ -16,7 +16,8 @@ class CurlHelper { CurlHandle::Ptr newCurl() const; private: - static void setopt(CurlHandle::Ptr, CURLoption, const char *); + static void setopt_s(CurlHandle::Ptr, CURLoption, const char *); + static void setopt_l(CurlHandle::Ptr, CURLoption, int64_t); const Variable userAgent; const Variable cookieJar; @@ -24,6 +25,7 @@ class CurlHelper { const Variable method; const Variable userName; const Variable password; + const Variable timeout; }; #endif -- cgit v1.2.3