From 419f903ff44a22debba43976baae1e86c1e5d871 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 16 Jul 2012 06:47:59 +0000 Subject: Add a timeout property to the CURL HTTP clients. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1361916 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/components/http/httpdelete.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'sca-cpp/trunk/components/http/httpdelete.cpp') diff --git a/sca-cpp/trunk/components/http/httpdelete.cpp b/sca-cpp/trunk/components/http/httpdelete.cpp index d78a4d60df..c725461ec2 100644 --- a/sca-cpp/trunk/components/http/httpdelete.cpp +++ b/sca-cpp/trunk/components/http/httpdelete.cpp @@ -37,7 +37,7 @@ namespace httpdelete { /** * Evaluate an HTTP delete. */ -const failable get(const lambda&)> url, http::CURLSession& ch) { +const failable get(const lambda&)>& url, http::CURLSession& ch) { debug("httpdelete::get"); const value u = url(mklist("get", list())); debug(u, "httpdelete::get::url"); @@ -49,7 +49,7 @@ const failable get(const lambda&)> url, http::CUR */ class applyhttp { public: - applyhttp(const lambda&)> url, const perthread_ptr& ch) : url(url), ch(ch) { + applyhttp(const lambda&)>& url, const perthread_ptr& ch) : url(url), ch(ch) { } const value operator()(const list& params) const { @@ -68,16 +68,24 @@ private: /** * Create a new CURL session. */ -const gc_ptr newsession() { - return new (gc_new()) http::CURLSession("", "", "", ""); -} +class newsession { +public: + newsession(const lambda&)>& timeout) : timeout(timeout) { + } + const gc_ptr operator()() const { + const int t = atoi(c_str((string)timeout(list()))); + return new (gc_new()) http::CURLSession("", "", "", "", t); + } +private: + const lambda&)> timeout; +}; /** * Start the component. */ const failable start(const list& params) { // Create a CURL session - const perthread_ptr ch = perthread_ptr(lambda()>(newsession)); + const perthread_ptr ch = perthread_ptr(lambda()>(newsession(cadr(params)))); // Return the component implementation lambda function return value(lambda&)>(applyhttp(car(params), ch))); -- cgit v1.2.3