summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components/http/httpget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/components/http/httpget.cpp')
-rw-r--r--sca-cpp/trunk/components/http/httpget.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/sca-cpp/trunk/components/http/httpget.cpp b/sca-cpp/trunk/components/http/httpget.cpp
index 8515d6f41e..884dc1a6ff 100644
--- a/sca-cpp/trunk/components/http/httpget.cpp
+++ b/sca-cpp/trunk/components/http/httpget.cpp
@@ -38,7 +38,7 @@ namespace httpget {
/**
* Evaluate an HTTP get.
*/
-const failable<value> get(const lambda<value(const list<value>&)> url, http::CURLSession& ch) {
+const failable<value> get(const lambda<value(const list<value>&)>& url, http::CURLSession& ch) {
debug("httpget::get");
const value u = url(mklist<value>("get", list<value>()));
debug(u, "httpget::get::url");
@@ -50,7 +50,7 @@ const failable<value> get(const lambda<value(const list<value>&)> url, http::CUR
*/
class applyhttp {
public:
- applyhttp(const lambda<value(const list<value>&)> url, const perthread_ptr<http::CURLSession>& ch) : url(url), ch(ch) {
+ applyhttp(const lambda<value(const list<value>&)>& url, const perthread_ptr<http::CURLSession>& ch) : url(url), ch(ch) {
}
const value operator()(const list<value>& params) const {
@@ -70,16 +70,24 @@ private:
/**
* Create a new CURL session.
*/
-const gc_ptr<http::CURLSession> newsession() {
- return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "");
-}
+class newsession {
+public:
+ newsession(const lambda<value(const list<value>&)>& timeout) : timeout(timeout) {
+ }
+ const gc_ptr<http::CURLSession> operator()() const {
+ const int t = atoi(c_str((string)timeout(list<value>())));
+ return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "", t);
+ }
+private:
+ const lambda<value(const list<value>&)> timeout;
+};
/**
* Start the component.
*/
const failable<value> start(const list<value>& params) {
// Create a CURL session
- const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession));
+ const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(cadr(params))));
// Return the component implementation lambda function
return value(lambda<value(const list<value>&)>(applyhttp(car(params), ch)));