diff options
Diffstat (limited to 'sca-cpp/trunk/components/http/httpget.cpp')
-rw-r--r-- | sca-cpp/trunk/components/http/httpget.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/sca-cpp/trunk/components/http/httpget.cpp b/sca-cpp/trunk/components/http/httpget.cpp index ac7a99775b..fc89784749 100644 --- a/sca-cpp/trunk/components/http/httpget.cpp +++ b/sca-cpp/trunk/components/http/httpget.cpp @@ -28,6 +28,7 @@ #include "list.hpp" #include "value.hpp" #include "monad.hpp" +#include "parallel.hpp" #include "../../modules/http/http.hpp" namespace tuscany { @@ -48,28 +49,36 @@ const failable<value> get(const lambda<value(const list<value>&)> url, http::CUR */ class applyhttp { public: - applyhttp(const lambda<value(const list<value>&)> url, 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 { debug(params, "httpget::applyhttp::params"); const value func(car(params)); if (func == "get") - return get(url, ch); + return get(url, *ch); return tuscany::mkfailure<tuscany::value>(); } private: const lambda<value(const list<value>&)> url; - http::CURLSession& ch; + perthread_ptr<http::CURLSession> ch; }; + +/** + * Create a new CURL session. + */ +const gc_ptr<http::CURLSession> newsession() { + return new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", ""); +} + /** * Start the component. */ const failable<value> start(const list<value>& params) { // Create a CURL session - http::CURLSession& ch = *(new (gc_new<http::CURLSession>()) http::CURLSession("", "", "", "")); + const perthread_ptr<http::CURLSession> ch = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession)); // Return the component implementation lambda function return value(lambda<value(const list<value>&)>(applyhttp(car(params), ch))); |