diff options
Diffstat (limited to 'sca-cpp/trunk/modules')
-rw-r--r-- | sca-cpp/trunk/modules/atom/atom.hpp | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/http/curl.hpp | 18 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/json/json.hpp | 6 |
3 files changed, 14 insertions, 14 deletions
diff --git a/sca-cpp/trunk/modules/atom/atom.hpp b/sca-cpp/trunk/modules/atom/atom.hpp index 22489fd1d1..7e2eb66cd2 100644 --- a/sca-cpp/trunk/modules/atom/atom.hpp +++ b/sca-cpp/trunk/modules/atom/atom.hpp @@ -115,7 +115,7 @@ const list<value> entriesElements(const list<value>& l) { * Convert a list of values representing an ATOM entry to an ATOM entry. * The first two values in the list are the entry id and title. */ -template<typename R> const failable<R, std::string> writeATOMEntry(const lambda<R(std::string, R)>& reduce, const R& initial, const list<value>& l) { +template<typename R> const failable<R, std::string> writeATOMEntry(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l) { return writeXML<R>(reduce, initial, mklist<value>(entryElement(l))); } @@ -130,7 +130,7 @@ const failable<list<std::string>, std::string> writeATOMEntry(const list<value>& * Convert a list of values representing an ATOM feed to an ATOM feed. * The first two values in the list are the feed id and title. */ -template<typename R> const failable<R, std::string> writeATOMFeed(const lambda<R(std::string, R)>& reduce, const R& initial, const list<value>& l) { +template<typename R> const failable<R, std::string> writeATOMFeed(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l) { const list<value> f = list<value>() << element << "feed" << (list<value>() << attribute << "xmlns" << "http://www.w3.org/2005/Atom") << (list<value>() << element << "title" << (list<value>() << attribute << "type" << "text") << car(l)) diff --git a/sca-cpp/trunk/modules/http/curl.hpp b/sca-cpp/trunk/modules/http/curl.hpp index fd2e9857d1..85665c2785 100644 --- a/sca-cpp/trunk/modules/http/curl.hpp +++ b/sca-cpp/trunk/modules/http/curl.hpp @@ -35,6 +35,7 @@ #include "value.hpp" #include "element.hpp" #include "monad.hpp" +#include "parallel.hpp" #include "../atom/atom.hpp" #include "../json/json.hpp" @@ -126,9 +127,9 @@ size_t readCallback(void *ptr, size_t size, size_t nmemb, void *data) { */ template<typename R> class CURLWriteContext { public: - CURLWriteContext(const lambda<R(std::string, R)>& reduce, const R& accum) : reduce(reduce), accum(accum) { + CURLWriteContext(const lambda<R(const std::string&, const R)>& reduce, const R& accum) : reduce(reduce), accum(accum) { } - const lambda<R(std::string, R)> reduce; + const lambda<R(const std::string&, const R)> reduce; R accum; }; @@ -162,7 +163,7 @@ curl_slist* headers(curl_slist* cl, const list<std::string>& h) { return headers(curl_slist_append(cl, std::string(car(h)).c_str()), cdr(h)); } -template<typename R> const failable<list<R>, std::string> apply(const list<list<std::string> >& req, const lambda<R(std::string, R)>& reduce, const R& initial, const std::string& url, const std::string& verb, const CURLSession& cs) { +template<typename R> const failable<list<R>, std::string> apply(const list<list<std::string> >& req, const lambda<R(const std::string&, const R)>& reduce, const R& initial, const std::string& url, const std::string& verb, const CURLSession& cs) { // Init the curl session CURL* ch = handle(cs); @@ -174,8 +175,6 @@ template<typename R> const failable<list<R>, std::string> apply(const list<list< write(cadr(req), os); const std::string s = os.str(); const int sz = s.length(); - if (sz < 1400) - curl_easy_setopt(ch, CURLOPT_TCP_NODELAY, true); // Setup the read, header and write callbacks CURLReadContext rcx(mklist(s)); @@ -187,6 +186,7 @@ template<typename R> const failable<list<R>, std::string> apply(const list<list< CURLWriteContext<R> wcx(reduce, initial); curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, (size_t (*)(void*, size_t, size_t, void*))writeCallback<R>); curl_easy_setopt(ch, CURLOPT_WRITEDATA, &wcx); + curl_easy_setopt(ch, CURLOPT_TCP_NODELAY, true); // Set the request headers curl_slist* hl = headers(NULL, car(req)); @@ -291,7 +291,7 @@ const failable<std::string, std::string> contentType(const list<std::string>& h) /** * HTTP GET, return the resource at the given URL. */ -template<typename R> const failable<list<R>, std::string> get(const lambda<R(std::string, R)>& reduce, const R& initial, const std::string& url, const CURLSession& ch) { +template<typename R> const failable<list<R>, std::string> get(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const std::string& url, const CURLSession& ch) { debug(url, "http::get::url"); const list<list<std::string> > req = mklist(list<std::string>(), list<std::string>()); return apply(req, reduce, initial, url, "GET", ch); @@ -391,18 +391,18 @@ const failable<value, std::string> del(const std::string& url, const CURLSession * HTTP client proxy function. */ struct proxy { - proxy(const std::string& url, const CURLSession& ch) : url(url), ch(ch) { + proxy(const std::string& url) : url(url) { } const value operator()(const list<value>& args) const { - failable<value, std::string> val = evalExpr(args, url, ch); + CURLSession cs; + failable<value, std::string> val = evalExpr(args, url, cs); if (!hasContent(val)) return value(); return content(val); } const std::string url; - const CURLSession ch; }; } diff --git a/sca-cpp/trunk/modules/json/json.hpp b/sca-cpp/trunk/modules/json/json.hpp index 7d9bba564e..6ce4e3a9a1 100644 --- a/sca-cpp/trunk/modules/json/json.hpp +++ b/sca-cpp/trunk/modules/json/json.hpp @@ -332,10 +332,10 @@ const failable<bool, std::string> writeList(const list<value>& l, JSObject* o, c */ template<typename R> class WriteContext { public: - WriteContext(const lambda<R(std::string, R)>& reduce, const R& accum, const JSONContext& cx) : cx(cx), reduce(reduce), accum(accum) { + WriteContext(const lambda<R(const std::string&, const R)>& reduce, const R& accum, const JSONContext& cx) : cx(cx), reduce(reduce), accum(accum) { } const JSONContext& cx; - const lambda<R(std::string, R)> reduce; + const lambda<R(const std::string&, const R)> reduce; R accum; }; @@ -352,7 +352,7 @@ template<typename R> JSBool writeCallback(const jschar *buf, uint32 len, void *d /** * Convert a list of values to a JSON document. */ -template<typename R> const failable<R, std::string> writeJSON(const lambda<R(std::string, R)>& reduce, const R& initial, const list<value>& l, const JSONContext& cx) { +template<typename R> const failable<R, std::string> writeJSON(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l, const JSONContext& cx) { JSObject* o = JS_NewObject(cx, NULL, NULL, NULL); jsval val = OBJECT_TO_JSVAL(o); const failable<bool, std::string> w = writeList(l, o, cx); |