summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/modules')
-rw-r--r--sca-cpp/trunk/modules/http/curl.hpp43
-rw-r--r--sca-cpp/trunk/modules/json/json.hpp13
-rw-r--r--sca-cpp/trunk/modules/server/mod-cpp.hpp9
3 files changed, 20 insertions, 45 deletions
diff --git a/sca-cpp/trunk/modules/http/curl.hpp b/sca-cpp/trunk/modules/http/curl.hpp
index 3478a590fd..d836eaa2f0 100644
--- a/sca-cpp/trunk/modules/http/curl.hpp
+++ b/sca-cpp/trunk/modules/http/curl.hpp
@@ -43,50 +43,37 @@ namespace tuscany {
namespace http {
/**
- * CURL library context, one per process.
+ * CURL library runtime, one per process.
*/
-class CURLContext {
+class CURLRuntime {
public:
- CURLContext() {
+ CURLRuntime() {
curl_global_init(CURL_GLOBAL_ALL);
}
- ~CURLContext() {
- curl_global_cleanup();
- }
-};
-
-CURLContext curlContext;
+} curlRuntime;
/**
* Represents a CURL session handle.
*/
class CURLSession {
public:
- CURLSession() : ch(new (gc_new<CURLHandle>()) CURLHandle()) {
+ CURLSession() : h(curl_easy_init()), owner(true) {
}
- ~CURLSession() {
+ CURLSession(const CURLSession& c) : h(c.h), owner(false) {
}
- CURLSession(const CURLSession& c) : ch(c.ch) {
+ ~CURLSession() {
+ if (!owner)
+ return;
+ if (h == NULL)
+ return;
+ curl_easy_cleanup(h);
}
private:
- class CURLHandle {
- public:
- CURLHandle() : h(curl_easy_init()) {
- }
- ~CURLHandle() {
- curl_easy_cleanup(h);
- h = NULL;
- }
- private:
- CURL* h;
-
- friend CURL* handle(const CURLSession& c);
- };
-
- const gc_ptr<CURLHandle> ch;
+ CURL* h;
+ bool owner;
friend CURL* handle(const CURLSession& c);
};
@@ -95,7 +82,7 @@ private:
* Returns the CURL handle used by a CURL session.
*/
CURL* handle(const CURLSession& c) {
- return c.ch->h;
+ return c.h;
}
/**
diff --git a/sca-cpp/trunk/modules/json/json.hpp b/sca-cpp/trunk/modules/json/json.hpp
index 9124c5143c..e2f036541a 100644
--- a/sca-cpp/trunk/modules/json/json.hpp
+++ b/sca-cpp/trunk/modules/json/json.hpp
@@ -46,7 +46,7 @@ void reportError(unused JSContext *cx, const char *message, JSErrorReport *repor
}
/**
- * Encapsulates a JavaScript runtime. Can be shared by multiple threads in
+ * Encapsulates a JavaScript runtime. Shared by multiple threads in
* a process.
*/
class JSONRuntime {
@@ -58,9 +58,6 @@ public:
cleanup();
}
- ~JSONRuntime() {
- }
-
operator JSRuntime*() const {
return rt;
}
@@ -75,17 +72,11 @@ private:
}
JSRuntime* rt;
-};
-
-/**
- * Global JavaScript runtime instance.
- */
-JSONRuntime jsRuntime;
+} jsRuntime;
JSClass jsGlobalClass = { "global", JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, JSCLASS_NO_OPTIONAL_MEMBERS};
-
/**
* Represents a JavaScript context. Create one per thread.
*/
diff --git a/sca-cpp/trunk/modules/server/mod-cpp.hpp b/sca-cpp/trunk/modules/server/mod-cpp.hpp
index 2cf2e540d6..17d44e1428 100644
--- a/sca-cpp/trunk/modules/server/mod-cpp.hpp
+++ b/sca-cpp/trunk/modules/server/mod-cpp.hpp
@@ -65,14 +65,11 @@ struct evalImplementation {
* Read a C++ component implementation.
*/
const failable<lambda<value(const list<value>&)> > readImplementation(const string& path, const list<value>& px) {
- const failable<lib> ilib(dynlib(path + dynlibExt));
- if (!hasContent(ilib))
- return mkfailure<lambda<value(const list<value>&)> >(reason(ilib));
-
- const failable<lambda<value(const list<value>&)> > impl(dynlambda<value(const list<value>&)>("eval", content(ilib)));
+ const lib ilib(*(new (gc_new<lib>()) lib(path + dynlibExt)));
+ const failable<lambda<value(const list<value>&)> > impl(dynlambda<value(const list<value>&)>("eval", ilib));
if (!hasContent(impl))
return impl;
- return lambda<value(const list<value>&)>(evalImplementation(content(ilib), content(impl), px));
+ return lambda<value(const list<value>&)>(evalImplementation(ilib, content(impl), px));
}
}