1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00

some fix + UMongoDBClient find extension

This commit is contained in:
stefanocasazza 2016-05-16 15:40:17 +02:00
parent be68eeb09c
commit 4c2a92c11b
39 changed files with 596 additions and 551 deletions

View File

@ -152,11 +152,11 @@ public:
{ {
U_TRACE(0, "UCommand::getArgument(%d)", n) U_TRACE(0, "UCommand::getArgument(%d)", n)
char* result = (argv_exec ? argv_exec[n] : 0); char* arg = (argv_exec ? argv_exec[n] : 0);
U_INTERNAL_ASSERT(result == 0 || u_isText((const unsigned char*)result, u__strlen(result, __PRETTY_FUNCTION__))) U_INTERNAL_ASSERT(arg == 0 || u_isText((const unsigned char*)arg, u__strlen(arg, __PRETTY_FUNCTION__)))
U_RETURN(result); U_RETURN(arg);
} }
void setNumArgument(int32_t n = 1, bool bfree = false); void setNumArgument(int32_t n = 1, bool bfree = false);
@ -217,9 +217,9 @@ public:
U_INTERNAL_ASSERT(command) U_INTERNAL_ASSERT(command)
bool result = (strncmp(command.data(), U_CONSTANT_TO_PARAM(U_PATH_SHELL)) == 0); if (strncmp(command.data(), U_CONSTANT_TO_PARAM(U_PATH_SHELL)) == 0) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
char* getCommand() const __pure { return getArgument(isShellScript() ? 2 : 0); } char* getCommand() const __pure { return getArgument(isShellScript() ? 2 : 0); }
@ -252,9 +252,9 @@ public:
U_INTERNAL_ASSERT_POINTER(argv_exec) U_INTERNAL_ASSERT_POINTER(argv_exec)
bool result = (U_SYSCALL(access, "%S,%d", argv_exec[0], mode) == 0); if (U_SYSCALL(access, "%S,%d", argv_exec[0], mode) == 0) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
// MANAGE MESSAGE ERROR // MANAGE MESSAGE ERROR
@ -263,18 +263,18 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UCommand::isStarted()") U_TRACE_NO_PARAM(0, "UCommand::isStarted()")
bool result = (pid > 0); if (pid > 0) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
static bool isTimeout() static bool isTimeout()
{ {
U_TRACE_NO_PARAM(0, "UCommand::isTimeout()") U_TRACE_NO_PARAM(0, "UCommand::isTimeout()")
bool result = (exit_value == -EAGAIN); if (exit_value == -EAGAIN) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
static void printMsgError() static void printMsgError()

View File

@ -851,6 +851,11 @@ public:
UHashMap<UStringRep*>::insertAfterFind(_key, str.rep); UHashMap<UStringRep*>::insertAfterFind(_key, str.rep);
} }
// OPERATOR
bool operator==(const UHashMap<UString>& v) __pure;
bool operator!=(const UHashMap<UString>& v) { return ! operator==(v); }
// OPERATOR [] // OPERATOR []
UString operator[](const char* _key); UString operator[](const char* _key);

View File

@ -53,9 +53,9 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UPlugIn<void*>::empty()") U_TRACE_NO_PARAM(0, "UPlugIn<void*>::empty()")
bool result = (first == 0); if (first == 0) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
static UPlugIn<void*>* getObjWrapper(void* obj) __pure; static UPlugIn<void*>* getObjWrapper(void* obj) __pure;

View File

@ -530,8 +530,10 @@ public:
static int jread_error; static int jread_error;
static uint32_t jread_elements, jread_pos; static uint32_t jread_elements, jread_pos;
static bool jfind(const UString& json, const UString& query, UString& result); static int jread(const UString& json, const UString& query, UString& result, uint32_t* queryParams = 0);
static int jread(const UString& json, const UString& query, UString& result, uint32_t* queryParams = 0); static bool jfind(const UString& json, const char* query, uint32_t quey_len, UString& result);
static bool jfind(const UString& json, const UString& query, UString& result) { return jfind(json, U_STRING_TO_PARAM(query), result); }
// reads one value from an array // reads one value from an array

View File

@ -82,9 +82,9 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UMimeEntity::isEmpty()") U_TRACE_NO_PARAM(0, "UMimeEntity::isEmpty()")
bool result = content.empty(); if (content.empty()) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
void clear() void clear()
@ -189,21 +189,27 @@ public:
UString value = getContentDisposition(); UString value = getContentDisposition();
bool result = (value.empty() == false && if (value.empty() == false &&
U_STRING_FIND(value, 0, "attachment") != U_NOT_FOUND); U_STRING_FIND(value, 0, "attachment") != U_NOT_FOUND)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool isBodyMessage() const bool isBodyMessage() const
{ {
U_TRACE_NO_PARAM(0, "UMimeEntity::isBodyMessage()") U_TRACE_NO_PARAM(0, "UMimeEntity::isBodyMessage()")
bool result = (isText() && if (isText() &&
UMimeHeader::getValueAttributeFromKeyValue(content_type, U_CONSTANT_TO_PARAM("name"), false).empty() && UMimeHeader::getValueAttributeFromKeyValue(content_type, U_CONSTANT_TO_PARAM("name"), false).empty() &&
isAttachment() == false); isAttachment() == false)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
UString getFileName() const { return UMimeHeader::getFileName(getContentDisposition()); } UString getFileName() const { return UMimeHeader::getFileName(getContentDisposition()); }
@ -312,9 +318,9 @@ public:
// DEBUG // DEBUG
# ifdef DEBUG # ifdef DEBUG
const char* dump(bool reset) const; const char* dump(bool reset) const;
# endif # endif
#endif #endif
protected: protected:
@ -391,9 +397,9 @@ public:
// DEBUG // DEBUG
# ifdef DEBUG # ifdef DEBUG
const char* dump(bool reset) const; const char* dump(bool reset) const;
# endif # endif
#endif #endif
protected: protected:
@ -414,9 +420,13 @@ protected:
{ {
U_TRACE_NO_PARAM(0, "UMimeMultipart::isEmpty()") U_TRACE_NO_PARAM(0, "UMimeMultipart::isEmpty()")
bool result = (UMimeEntity::isEmpty() && getNumBodyPart() == 0); if (UMimeEntity::isEmpty() &&
getNumBodyPart() == 0)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
void setEmpty() void setEmpty()

View File

@ -189,9 +189,10 @@ public:
U_ASSERT(empty() == false) U_ASSERT(empty() == false)
bool result = getHeader(U_CONSTANT_TO_PARAM("Connection")).equal(U_CONSTANT_TO_PARAM("close")); if (getHeader(U_CONSTANT_TO_PARAM("Connection")).equal(U_CONSTANT_TO_PARAM("close")))
U_RETURN(result); U_RETURN(true);
U_RETURN(false);
} }
// Transfer-Encoding: chunked // Transfer-Encoding: chunked
@ -202,9 +203,9 @@ public:
U_ASSERT(empty() == false) U_ASSERT(empty() == false)
bool result = (getHeader(U_CONSTANT_TO_PARAM("Transfer-Encoding")) == *UString::str_chunked); if (getHeader(U_CONSTANT_TO_PARAM("Transfer-Encoding")) == *UString::str_chunked) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
// Cookie // Cookie
@ -228,9 +229,9 @@ public:
U_ASSERT(empty() == false) U_ASSERT(empty() == false)
bool result = containsHeader(U_CONSTANT_TO_PARAM("Set-Cookie")); if (containsHeader(U_CONSTANT_TO_PARAM("Set-Cookie"))) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
// Location // Location
@ -276,10 +277,13 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UMimeHeader::isMime()") U_TRACE_NO_PARAM(0, "UMimeHeader::isMime()")
bool result = ((table.empty() == false) && if (table.empty() == false &&
(getMimeVersion().empty() == false)); getMimeVersion().empty() == false)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
/** /**
@ -311,10 +315,11 @@ public:
if (content_type) if (content_type)
{ {
bool result = (ignore_case ? u__strncasecmp(content_type.data(), type, len) if ((ignore_case ? u__strncasecmp(content_type.data(), type, len)
: strncmp(content_type.data(), type, len)) == 0; : strncmp(content_type.data(), type, len)) == 0)
{
U_RETURN(result); U_RETURN(true);
}
} }
U_RETURN(false); U_RETURN(false);

View File

@ -129,9 +129,7 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UClient_Base::reset()") U_TRACE_NO_PARAM(0, "UClient_Base::reset()")
# ifdef DEBUG
uri.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE... (uri can be a substr of url) uri.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE... (uri can be a substr of url)
# endif
url.clear(); url.clear();
} }

View File

@ -101,9 +101,9 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UHttpClient_Base::isPasswordAuthentication()") U_TRACE_NO_PARAM(0, "UHttpClient_Base::isPasswordAuthentication()")
bool result = (user && password); if (user && password) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
void setRequestPasswordAuthentication(const UString& _user, const UString& _password) void setRequestPasswordAuthentication(const UString& _user, const UString& _password)

View File

@ -82,7 +82,7 @@ public:
BSON_APPEND_INT32(query, "_id", value); BSON_APPEND_INT32(query, "_id", value);
bool result = find(query); bool result = find(query, 0);
U_SYSCALL_VOID(bson_destroy, "%p", query); U_SYSCALL_VOID(bson_destroy, "%p", query);
@ -102,7 +102,7 @@ public:
bson_t* query = (bson_t*) U_SYSCALL_NO_PARAM(bson_new); bson_t* query = (bson_t*) U_SYSCALL_NO_PARAM(bson_new);
bool result = find(query); bool result = find(query, 0);
U_SYSCALL_VOID(bson_destroy, "%p", query); U_SYSCALL_VOID(bson_destroy, "%p", query);
@ -122,6 +122,8 @@ public:
bool findOne(const char* json, uint32_t len); bool findOne(const char* json, uint32_t len);
bool find(bson_t* query, bson_t* projection);
bool update(bson_t* query, bson_t* update); bool update(bson_t* query, bson_t* update);
bool findAndModify(bson_t* query, bson_t* update); bool findAndModify(bson_t* query, bson_t* update);
@ -143,8 +145,6 @@ protected:
mongoc_client_t* client; mongoc_client_t* client;
mongoc_cursor_t* cursor; mongoc_cursor_t* cursor;
mongoc_collection_t* collection; mongoc_collection_t* collection;
bool find(bson_t* query);
#endif #endif
private: private:

View File

@ -125,9 +125,13 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UIPAllow::isEmpty()") U_TRACE_NO_PARAM(0, "UIPAllow::isEmpty()")
bool result = (device.empty() || host.empty()); if (device.empty() ||
host.empty())
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
static bool getNetworkInterface(UVector<UIPAllow*>& vipallow); static bool getNetworkInterface(UVector<UIPAllow*>& vipallow);
@ -292,11 +296,14 @@ public:
{ {
U_TRACE(0, "UIPAddress::operator==(%p)", &cOtherAddr) U_TRACE(0, "UIPAddress::operator==(%p)", &cOtherAddr)
bool result = (iAddressType == cOtherAddr.iAddressType) && if (iAddressType == cOtherAddr.iAddressType &&
(iAddressLength == cOtherAddr.iAddressLength) && iAddressLength == cOtherAddr.iAddressLength &&
(memcmp(pcAddress.p, cOtherAddr.pcAddress.p, iAddressLength) == 0); (memcmp(pcAddress.p, cOtherAddr.pcAddress.p, iAddressLength) == 0))
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool operator!=(const UIPAddress& cOtherAddr) const { return !operator==(cOtherAddr); } bool operator!=(const UIPAddress& cOtherAddr) const { return !operator==(cOtherAddr); }

View File

@ -107,19 +107,26 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UTimeVal::isZero()") U_TRACE_NO_PARAM(0, "UTimeVal::isZero()")
bool result = (tv_sec == 0L && if (tv_sec == 0L &&
tv_usec <= 1L); tv_usec <= 1L)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool isNegativ() const bool isNegativ() const
{ {
U_TRACE_NO_PARAM(0,"UTimeVal::isNegativ()") U_TRACE_NO_PARAM(0,"UTimeVal::isNegativ()")
bool result = (tv_sec < 0L || tv_usec < 0L); if (tv_sec < 0L ||
tv_usec < 0L)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool notZero() const { return (isZero() == false); } bool notZero() const { return (isZero() == false); }
@ -155,9 +162,9 @@ public:
U_CHECK_MEMORY U_CHECK_MEMORY
long result = tv_sec + (tv_usec >= 500000L ? 1L : 0L); long sec = tv_sec + (tv_usec >= 500000L ? 1L : 0L);
U_RETURN(result); U_RETURN(sec);
} }
long getMilliSecond() const long getMilliSecond() const
@ -204,9 +211,13 @@ public:
U_CHECK_MEMORY U_CHECK_MEMORY
bool result = (tv_sec == t.tv_sec && tv_usec == t.tv_usec); if (tv_sec == t.tv_sec &&
tv_usec == t.tv_usec)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool operator==(const UTimeVal& t) const bool operator==(const UTimeVal& t) const
@ -215,9 +226,13 @@ public:
U_CHECK_MEMORY U_CHECK_MEMORY
bool result = (tv_sec == t.tv_sec && tv_usec == t.tv_usec); if (tv_sec == t.tv_sec &&
tv_usec == t.tv_usec)
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool operator< (const UTimeVal& t) const __pure; bool operator< (const UTimeVal& t) const __pure;
@ -343,10 +358,14 @@ public:
U_INTERNAL_ASSERT_RANGE(0L, tv_usec, U_SECOND) U_INTERNAL_ASSERT_RANGE(0L, tv_usec, U_SECOND)
bool result = (tv_sec > t->tv_sec || if ( tv_sec > t->tv_sec ||
(tv_sec == t->tv_sec && ((tv_usec * 1000L) > t->tv_nsec))); (tv_sec == t->tv_sec &&
((tv_usec * 1000L) > t->tv_nsec)))
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
// SERVICES // SERVICES

View File

@ -60,9 +60,9 @@ public:
{ {
U_TRACE_NO_PARAM(0, "UTokenizer::atEnd()") U_TRACE_NO_PARAM(0, "UTokenizer::atEnd()")
bool result = (s >= end); if (s >= end) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
void setDelimiter(const char* sep) void setDelimiter(const char* sep)

View File

@ -148,13 +148,13 @@ public:
void set(const Url& u) void set(const Url& u)
{ {
service_end = u.service_end; service_end = u.service_end;
user_begin = u.user_begin; user_begin = u.user_begin;
user_end = u.user_end; user_end = u.user_end;
host_begin = u.host_begin; host_begin = u.host_begin;
host_end = u.host_end; host_end = u.host_end;
path_begin = u.path_begin; path_begin = u.path_begin;
path_end = u.path_end; path_end = u.path_end;
query = u.query; query = u.query;
} }
Url(const Url& u) : url(u.url) Url(const Url& u) : url(u.url)
@ -198,7 +198,14 @@ public:
url.clear(); url.clear();
service_end = user_begin = user_end = host_begin = host_end = path_begin = path_end = query = -1; service_end =
user_begin =
user_end =
host_begin =
host_end =
path_begin =
path_end =
query = -1;
} }
/** /**
@ -216,36 +223,45 @@ public:
{ {
U_TRACE_NO_PARAM(0, "Url::isHTTP()") U_TRACE_NO_PARAM(0, "Url::isHTTP()")
bool result = (getService() == *UString::str_http); if (service_end == 4 &&
UString::str_http->equal(url.data(), (uint32_t)service_end))
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool isHTTPS() const bool isHTTPS() const
{ {
U_TRACE_NO_PARAM(0, "Url::isHTTPS()") U_TRACE_NO_PARAM(0, "Url::isHTTPS()")
bool result = getService().equal(U_CONSTANT_TO_PARAM("https")); if (service_end == 5 &&
url.c_char(4) == 's' &&
UString::str_http->equal(url.data(), 4))
{
U_RETURN(true);
}
U_RETURN(result); U_RETURN(false);
} }
bool isLDAP() const bool isLDAP() const
{ {
U_TRACE_NO_PARAM(0, "Url::isLDAP()") U_TRACE_NO_PARAM(0, "Url::isLDAP()")
bool result = getService().equal(U_CONSTANT_TO_PARAM("ldap")); if (getService().equal(U_CONSTANT_TO_PARAM("ldap"))) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
bool isLDAPS() const bool isLDAPS() const
{ {
U_TRACE_NO_PARAM(0, "Url::isLDAPS()") U_TRACE_NO_PARAM(0, "Url::isLDAPS()")
bool result = getService().equal(U_CONSTANT_TO_PARAM("ldaps")); if (getService().equal(U_CONSTANT_TO_PARAM("ldaps"))) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
/** /**
@ -304,9 +320,11 @@ public:
{ {
U_TRACE_NO_PARAM(0, "Url::isLocalFile()") U_TRACE_NO_PARAM(0, "Url::isLocalFile()")
bool result = (host_begin < host_end ? true : false); // Is there a host ? // Is there a host ?
U_RETURN(result); if (host_begin < host_end) U_RETURN(true);
U_RETURN(false);
} }
/** /**
@ -364,9 +382,9 @@ public:
{ {
U_TRACE_NO_PARAM(0, "Url::isPath()") U_TRACE_NO_PARAM(0, "Url::isPath()")
bool result = (path_begin < path_end); if (path_begin < path_end) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
/** /**
@ -412,9 +430,9 @@ public:
{ {
U_TRACE_NO_PARAM(0, "Url::isQuery()") U_TRACE_NO_PARAM(0, "Url::isQuery()")
bool result = (path_end < (int)(url.size() - 1)); if (path_end < (int)(url.size() - 1)) U_RETURN(true);
U_RETURN(result); U_RETURN(false);
} }
/** /**

View File

@ -542,6 +542,48 @@ UString UHashMap<UString>::erase(const UString& _key)
return UString::getStringNull(); return UString::getStringNull();
} }
__pure bool UHashMap<UString>::operator==(const UHashMap<UString>& t)
{
U_TRACE(0, "UHashMap<UString>::operator==(%p)", &t)
U_CHECK_MEMORY
if (_length == t._length)
{
U_INTERNAL_DUMP("_length = %u", _length)
UHashMapNode* _node;
UHashMapNode* _next;
UHashMapNode** ptr;
UHashMapNode** end;
for (end = (ptr = t.table) + t._capacity; ptr < end; ++ptr)
{
if (*ptr)
{
_node = *ptr;
do {
_next = _node->next;
UHashMap<void*>::lookup((UStringRep*)_node->key);
if (node == 0 ||
((UStringRep*)_node->elem)->equal(elem()) == false)
{
U_RETURN(false);
}
}
while ((_node = _next));
}
}
U_RETURN(true);
}
U_RETURN(false);
}
// OPERATOR [] // OPERATOR []
UString UHashMap<UString>::at(const UStringRep* _key) UString UHashMap<UString>::at(const UStringRep* _key)

View File

@ -2011,19 +2011,19 @@ end:
U_RETURN(jTok); U_RETURN(jTok);
} }
bool UValue::jfind(const UString& json, const UString& query, UString& result) bool UValue::jfind(const UString& json, const char* query, uint32_t query_len, UString& result)
{ {
U_TRACE(0, "UValue::jfind(%V,%V,%p)", json.rep, query.rep, &result) U_TRACE(0, "UValue::jfind(%V,%.*S,%u,%p)", json.rep, query_len, query, query_len, &result)
U_ASSERT(result.empty()) U_ASSERT(result.empty())
uint32_t pos = json.find(query); uint32_t pos = json.find(query, query_len);
U_INTERNAL_DUMP("pos = %d", pos) U_INTERNAL_DUMP("pos = %d", pos)
if (pos != U_NOT_FOUND) if (pos != U_NOT_FOUND)
{ {
pos += query.size(); pos += query_len;
if (u__isquote(json.c_char(pos))) ++pos; if (u__isquote(json.c_char(pos))) ++pos;
@ -2046,7 +2046,17 @@ bool UValue::jfind(const UString& json, const UString& query, UString& result)
if (jread_skip(tok) != -1) if (jread_skip(tok) != -1)
{ {
(void) result.assign(start, tok.getPointer()-start); const char* end = tok.getPointer();
if (u__isquote(*start))
{
++start;
--end;
U_INTERNAL_ASSERT(u__isquote(*end))
}
(void) result.assign(start, end-start);
U_RETURN(true); U_RETURN(true);
} }

View File

@ -357,43 +357,47 @@ bool UClient_Base::setUrl(const char* str, uint32_t len)
U_INTERNAL_ASSERT_POINTER(str) U_INTERNAL_ASSERT_POINTER(str)
U_INTERNAL_ASSERT_MAJOR(len, 0) U_INTERNAL_ASSERT_MAJOR(len, 0)
// check we've been passed a absolute URL // we check we've been passed a absolute URL
if (u_isUrlScheme(str, len) == 0) if (u_isUrlScheme(str, len) == 0)
{ {
char* p;
char* ptr;
char* dest;
uint32_t sz;
char buf[U_PATH_MAX];
const char* src = uri.data();
const char* _end = src + uri.size();
U_INTERNAL_DUMP("uri = %V", uri.rep) U_INTERNAL_DUMP("uri = %V", uri.rep)
ptr = dest = buf; if (uri.empty()) (void) uri.replace(str, len);
else
while (src < _end)
{ {
p = (char*) memchr(src, '/', _end - src); char* p;
char* ptr;
char* dest;
uint32_t sz;
char buf[U_PATH_MAX];
if (p == 0) break; const char* src = uri.data();
const char* _end = src + uri.size();
sz = p - src + 1; ptr = dest = buf;
U_INTERNAL_DUMP("segment = %.*S", sz, src) while (src < _end)
{
p = (char*) memchr(src, '/', _end - src);
U_MEMCPY(dest, src, sz); if (p == 0) break;
src = p + 1; sz = p - src + 1;
dest += sz;
U_INTERNAL_DUMP("segment = %.*S", sz, src)
U_MEMCPY(dest, src, sz);
src = p + 1;
dest += sz;
}
U_MEMCPY(dest, str, len);
(void) uri.replace(buf, dest - ptr + len);
} }
U_MEMCPY(dest, str, len);
(void) uri.replace(buf, dest - ptr + len);
U_INTERNAL_DUMP("uri = %V", uri.rep) U_INTERNAL_DUMP("uri = %V", uri.rep)
U_RETURN(false); U_RETURN(false);

View File

@ -953,9 +953,16 @@ bool UHttpClient_Base::sendRequest(int method, const char* content_type, uint32_
// send post request to server and get response // send post request to server and get response
if (sendRequest()) U_RETURN(true); bool ok = sendRequest();
U_RETURN(false); // reset reference to request...
UClient_Base::reset();
requestHeader->clear();
responseHeader->clear();
U_RETURN(ok);
} }
bool UHttpClient_Base::sendPost(const UString& _url, const UString& _body, const char* content_type, uint32_t content_type_len) bool UHttpClient_Base::sendPost(const UString& _url, const UString& _body, const char* content_type, uint32_t content_type_len)

View File

@ -78,14 +78,27 @@ bool UMongoDBClient::insert(bson_t* doc)
U_RETURN(false); U_RETURN(false);
} }
bool UMongoDBClient::find(bson_t* query) bool UMongoDBClient::find(bson_t* query, bson_t* projection)
{ {
U_TRACE(0, "UMongoDBClient::find(%p)", query) U_TRACE(0, "UMongoDBClient::find(%p,%p)", query, projection)
U_INTERNAL_ASSERT_POINTER(client) U_INTERNAL_ASSERT_POINTER(client)
U_INTERNAL_ASSERT_POINTER(collection) U_INTERNAL_ASSERT_POINTER(collection)
cursor = (mongoc_cursor_t*) U_SYSCALL(mongoc_collection_find, "%p,%d,%u,%u,%u,%p,%p,%p", collection, MONGOC_QUERY_NONE, 0, 0, 0, query, 0, 0); /**
* Parameters
*
* collection A mongoc_collection_t
* flags A mongoc_query_flags_t
* skip A uint32_t of number of documents to skip or 0
* limit A uint32_t of max number of documents to return or 0
* batch_size A uint32_t containing batch size of document result sets or 0 for default. Default is 100
* query A bson_t containing the query and options to execute
* fields A bson_t containing fields to return or NULL
* read_prefs A mongoc_read_prefs_t or NULL for default read preferences
*/
cursor = (mongoc_cursor_t*) U_SYSCALL(mongoc_collection_find, "%p,%d,%u,%u,%u,%p,%p,%p", collection, MONGOC_QUERY_NONE, 0, 0, 0, query, projection, 0);
if (cursor) if (cursor)
{ {
@ -143,7 +156,7 @@ bool UMongoDBClient::findOne(const char* json, uint32_t len)
} }
else else
{ {
bool result = find(bson); bool result = find(bson, 0);
U_SYSCALL_VOID(bson_destroy, "%p", bson); U_SYSCALL_VOID(bson_destroy, "%p", bson);

View File

@ -5,8 +5,6 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static World* pworld;
static UString* jquery;
static char buffer[128]; static char buffer[128];
static UElasticSearchClient* es; static UElasticSearchClient* es;
@ -29,14 +27,11 @@ static void usp_fork_edb()
return; return;
} }
U_NEW(World, pworld, World); u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("randomNumber"));
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(OBJECT_VALUE)); U_NEW(UValue, pvalue, UValue(OBJECT_VALUE));
#endif #endif
u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
@ -46,15 +41,9 @@ static void usp_end_edb()
delete es; delete es;
if (pworld) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue) delete pvalue;
delete jquery; #endif
delete pworld;
# ifndef AS_cpoll_cppsp_DO
delete pvalue;
# endif
}
} }
#endif #endif
--> -->
@ -62,18 +51,18 @@ static void usp_end_edb()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString result; UString result;
(void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, QLEN+u__snprintf(buffer+QLEN, 128, "%u\"}}}", pworld->id = u_get_num_random(10000-1))); (void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, u__snprintf(buffer+QLEN, 128, "%u\"}}}", id = u_get_num_random(10000-1))+QLEN);
(void) UValue::jfind(es->getContent(), *jquery, result); (void) UValue::jfind(es->getContent(), U_CONSTANT_TO_PARAM("randomNumber"), result);
pworld->randomNumber = u_strtoul(result.data(), result.end());
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", pworld->id, result.rep); USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, result.rep);
#else #else
USP_JSON_stringify(*pvalue, World, *pworld); World world(id, u_strtoul(result.data(), result.end()));
USP_JSON_stringify(*pvalue, World, world);
pvalue->clear(); pvalue->clear();
#endif #endif
--> -->

View File

@ -5,9 +5,7 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static UString* jquery;
static char buffer[128]; static char buffer[128];
static World* pworld_query;
static UElasticSearchClient* es; static UElasticSearchClient* es;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
@ -30,15 +28,12 @@ static void usp_fork_equery()
return; return;
} }
U_NEW(World, pworld_query, World); u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("randomNumber"));
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
#endif #endif
u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
@ -48,16 +43,13 @@ static void usp_end_equery()
delete es; delete es;
if (jquery) #ifndef AS_cpoll_cppsp_DO
if (pvalue)
{ {
delete jquery;
delete pworld_query;
# ifndef AS_cpoll_cppsp_DO
delete pvalue; delete pvalue;
delete pvworld_query; delete pvworld_query;
# endif
} }
#endif
} }
#endif #endif
--> -->
@ -65,6 +57,7 @@ static void usp_end_equery()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString rnumber; UString rnumber;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
@ -74,18 +67,18 @@ USP_PUTS_CHAR('[');
while (true) while (true)
{ {
(void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, QLEN+u__snprintf(buffer+QLEN, 128, "%u\"}}}", pworld_query->id = u_get_num_random(10000-1))); (void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, QLEN+u__snprintf(buffer+QLEN, 128, "%u\"}}}", id = u_get_num_random(10000-1)));
(void) UValue::jfind(es->getContent(), *jquery, rnumber); rnumber.clear();
(void) UValue::jfind(es->getContent(), U_CONSTANT_TO_PARAM("randomNumber"), rnumber);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", pworld_query->id, rnumber.rep); USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", id, rnumber.rep);
#else #else
pworld_query->randomNumber = u_strtoul(rnumber.data(), rnumber.end());
World* pworld; World* pworld;
U_NEW(World, pworld, World(*pworld_query)); U_NEW(World, pworld, World(id, u_strtoul(rnumber.data(), rnumber.end())));
pvworld_query->push_back(pworld); pvworld_query->push_back(pworld);
#endif #endif

View File

@ -5,9 +5,10 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static char* pbuffer1;
static char* pbuffer2;
static char buffer1[128]; static char buffer1[128];
static char buffer2[128]; static char buffer2[128];
static World* pworld_update;
static UElasticSearchClient* es; static UElasticSearchClient* es;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
@ -31,15 +32,18 @@ static void usp_fork_eupdate()
return; return;
} }
U_NEW(World, pworld_update, World); u__memcpy(buffer1, "/tfb/world/", ULEN, __PRETTY_FUNCTION__);
pbuffer1 = buffer1 + ULEN;
u__memcpy(buffer2, "{\"doc\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
pbuffer2 = buffer2 + QLEN;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
#endif #endif
u__memcpy(buffer1, "/tfb/world/", ULEN, __PRETTY_FUNCTION__);
u__memcpy(buffer2, "{\"doc\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
@ -49,15 +53,13 @@ static void usp_end_eupdate()
delete es; delete es;
if (pworld_update) #ifndef AS_cpoll_cppsp_DO
if (pvalue)
{ {
delete pworld_update;
# ifndef AS_cpoll_cppsp_DO
delete pvalue; delete pvalue;
delete pvworld_update; delete pvworld_update;
# endif
} }
#endif
} }
#endif #endif
--> -->
@ -65,7 +67,7 @@ static void usp_end_eupdate()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
World* pworld; uint32_t len1, len2, id, rnum;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
@ -74,14 +76,17 @@ USP_PUTS_CHAR('[');
while (true) while (true)
{ {
(void) es->sendPOST(buffer1, ULEN+u__snprintf(buffer1+ULEN, 128, "%u/_update", pworld_update->id = u_get_num_random(10000-1)), len1 = u__snprintf(pbuffer1, 100, "%u/_update", id = u_get_num_random(10000-1));
buffer2, QLEN+u__snprintf(buffer2+QLEN, 128, "%u\"}}", pworld_update->randomNumber = u_get_num_random(10000-1))); len2 = u__snprintf(pbuffer2, 100, "%u\"}}", rnum = u_get_num_random(10000-1));
(void) es->sendPOST(buffer1, len1+ULEN, buffer2, len2+QLEN);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", pworld_update->id, pworld_update->randomNumber); USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", id, rnum);
#else #else
World* pworld;
U_NEW(World, pworld, World(*pworld_update)); U_NEW(World, pworld, World(id, rnum));
pvworld_update->push_back(pworld); pvworld_update->push_back(pworld);
#endif #endif

View File

@ -5,8 +5,6 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static World* pworld;
static UString* jquery;
static UMongoDBClient* mc; static UMongoDBClient* mc;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
@ -33,9 +31,6 @@ static void usp_fork_mdb()
return; return;
} }
U_NEW(World, pworld, World);
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("{'randomNumber'"));
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(OBJECT_VALUE)); U_NEW(UValue, pvalue, UValue(OBJECT_VALUE));
#endif #endif
@ -48,15 +43,9 @@ static void usp_end_mdb()
delete mc; delete mc;
if (pworld) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue) delete pvalue;
delete pworld; #endif
delete jquery;
# ifndef AS_cpoll_cppsp_DO
delete pvalue;
# endif
}
} }
#endif #endif
--> -->
@ -64,18 +53,18 @@ static void usp_end_mdb()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString result; UString result;
(void) mc->findOne(pworld->id = u_get_num_random(10000-1)); (void) mc->findOne(id = u_get_num_random(10000-1));
(void) UValue::jread(mc->vitem[0], *jquery, result); // { "_id" : 8980.000000, "id" : 8980.000000, "randomNumber" : 2131.000000 } (void) UValue::jfind(mc->vitem[0], U_CONSTANT_TO_PARAM("randomNumber"), result);
pworld->randomNumber = u_strtoul(result.data(), result.end());
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", pworld->id, result.rep); USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, result.rep);
#else #else
USP_JSON_stringify(*pvalue, World, *pworld); World world(id, u_strtoul(result.data(), result.end()));
USP_JSON_stringify(*pvalue, World, world);
pvalue->clear(); pvalue->clear();
#endif #endif
--> -->

View File

@ -5,7 +5,6 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "fortune.h" #include "fortune.h"
static UString* jquery;
static UString* pencoded; static UString* pencoded;
static UMongoDBClient* mc; static UMongoDBClient* mc;
static Fortune* pfortune2add; static Fortune* pfortune2add;
@ -31,7 +30,6 @@ static void usp_fork_mfortune()
return; return;
} }
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("{'message'"));
U_NEW(UString, pencoded, UString(100U)); U_NEW(UString, pencoded, UString(100U));
U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>); U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>);
U_NEW(Fortune, pfortune2add, Fortune(0, U_STRING_FROM_CONSTANT("Additional fortune added at request time."))); U_NEW(Fortune, pfortune2add, Fortune(0, U_STRING_FROM_CONSTANT("Additional fortune added at request time.")));
@ -44,9 +42,8 @@ static void usp_end_mfortune()
delete mc; delete mc;
if (jquery) if (pencoded)
{ {
delete jquery;
delete pencoded; delete pencoded;
delete pvfortune; delete pvfortune;
delete pfortune2add; delete pfortune2add;
@ -60,15 +57,19 @@ uint32_t i, n;
UString result; UString result;
U_NEW(Fortune, item, Fortune(*pfortune2add)); U_NEW(Fortune, item, Fortune(*pfortune2add));
pvfortune->push_back(item); pvfortune->push_back(item);
(void) mc->findAll(); (void) mc->findAll();
for (i = 0, n = mc->vitem.size(); i < n; ++i) for (i = 0, n = mc->vitem.size(); i < n; ++i)
{ {
(void) UValue::jread(mc->vitem[i], *jquery, result); // { "_id" : 5.000000, "id" : 5.000000, "message" : "A computer program does what you tell it to do, not what you want it to do." } result.clear();
(void) UValue::jfind(mc->vitem[i], U_CONSTANT_TO_PARAM("message"), result);
U_NEW(Fortune, item, Fortune(i+1, result)); U_NEW(Fortune, item, Fortune(i+1, result));
pvfortune->push_back(item); pvfortune->push_back(item);
} }

View File

@ -5,9 +5,7 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static UString* jquery;
static UMongoDBClient* mc; static UMongoDBClient* mc;
static World* pworld_query;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
static UValue* pvalue; static UValue* pvalue;
@ -34,9 +32,6 @@ static void usp_fork_mquery()
return; return;
} }
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("{'randomNumber'"));
U_NEW(World, pworld_query, World);
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
@ -50,16 +45,13 @@ static void usp_end_mquery()
delete mc; delete mc;
if (jquery) #ifndef AS_cpoll_cppsp_DO
if (pvalue)
{ {
delete jquery;
delete pworld_query;
# ifndef AS_cpoll_cppsp_DO
delete pvalue; delete pvalue;
delete pvworld_query; delete pvworld_query;
# endif
} }
#endif
} }
#endif #endif
--> -->
@ -67,6 +59,7 @@ static void usp_end_mquery()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString rnumber; UString rnumber;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
@ -76,18 +69,18 @@ USP_PUTS_CHAR('[');
while (true) while (true)
{ {
(void) mc->findOne(pworld_query->id = u_get_num_random(10000-1)); (void) mc->findOne(id = u_get_num_random(10000-1));
(void) UValue::jread(mc->vitem[0], *jquery, rnumber); // { "_id" : 8980.000000, "id" : 8980.000000, "randomNumber" : 2131.000000 } rnumber.clear();
(void) UValue::jfind(mc->vitem[0], U_CONSTANT_TO_PARAM("randomNumber"), rnumber);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", pworld_query->id, rnumber.rep); USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", id, rnumber.rep);
#else #else
pworld_query->randomNumber = u_strtoul(rnumber.data(), rnumber.end());
World* pworld; World* pworld;
U_NEW(World, pworld, World(*pworld_query)); U_NEW(World, pworld, World(id, u_strtoul(rnumber.data(), rnumber.end())));
pvworld_query->push_back(pworld); pvworld_query->push_back(pworld);
#endif #endif

View File

@ -6,7 +6,6 @@ TechEmpower Web Framework Benchmarks
#include "world.h" #include "world.h"
static UMongoDBClient* mc; static UMongoDBClient* mc;
static World* pworld_update;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
static UValue* pvalue; static UValue* pvalue;
@ -33,8 +32,6 @@ static void usp_fork_mupdate()
return; return;
} }
U_NEW(World, pworld_update, World);
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
@ -48,15 +45,13 @@ static void usp_end_mupdate()
delete mc; delete mc;
if (pworld_update) #ifndef AS_cpoll_cppsp_DO
if (pvalue)
{ {
delete pworld_update;
# ifndef AS_cpoll_cppsp_DO
delete pvalue; delete pvalue;
delete pvworld_update; delete pvworld_update;
# endif
} }
#endif
} }
#endif #endif
--> -->
@ -64,6 +59,7 @@ static void usp_end_mupdate()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id, rnum;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
@ -72,17 +68,15 @@ USP_PUTS_CHAR('[');
while (true) while (true)
{ {
(void) mc->findOne(pworld_update->id = u_get_num_random(10000-1)); (void) mc->findOne( id = u_get_num_random(10000-1));
(void) mc->update(id, "randomNumber", rnum = u_get_num_random(10000-1));
(void) mc->update(pworld_update->id, "randomNumber", pworld_update->randomNumber = u_get_num_random(10000-1));
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", pworld_update->id, pworld_update->randomNumber); USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", id, rnum);
#else #else
World* pworld; World* pworld;
U_NEW(World, pworld, World(*pworld_update)); U_NEW(World, pworld, World(id, rnum));
pvworld_update->push_back(pworld); pvworld_update->push_back(pworld);
#endif #endif

View File

@ -5,7 +5,6 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static World* pworld;
static char buffer[128]; static char buffer[128];
static UREDISClient_Base* rc; static UREDISClient_Base* rc;
@ -26,13 +25,11 @@ static void usp_fork_rdb()
return; return;
} }
U_NEW(World, pworld, World); u__memcpy(buffer, "world:", U_CONSTANT_SIZE("world:"), __PRETTY_FUNCTION__);
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(OBJECT_VALUE)); U_NEW(UValue, pvalue, UValue(OBJECT_VALUE));
#endif #endif
u__memcpy(buffer, "world:", U_CONSTANT_SIZE("world:"), __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
@ -42,14 +39,9 @@ static void usp_end_rdb()
delete rc; delete rc;
if (pworld) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue) delete pvalue;
delete pworld; #endif
# ifndef AS_cpoll_cppsp_DO
delete pvalue;
# endif
}
} }
#endif #endif
--> -->
@ -57,18 +49,16 @@ static void usp_end_rdb()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
UStringRep* rep; uint32_t id;
(void) rc->get(buffer, 6+u_num2str32(buffer+6, pworld->id = u_get_num_random(10000-1))); (void) rc->get(buffer, 6+u_num2str32(buffer+6, id = u_get_num_random(10000-1)));
rep = rc->vitem[0].rep;
pworld->randomNumber = u_strtoul(rep->data(), rep->end());
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", pworld->id, rep); USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, rc->vitem[0].rep);
#else #else
USP_JSON_stringify(*pvalue, World, *pworld); UStringRep* rep = rc->vitem[0].rep;
World world(id, u_strtoul(rep->data(), rep->end()));
USP_JSON_stringify(*pvalue, World, world);
pvalue->clear(); pvalue->clear();
#endif #endif
--> -->

View File

@ -527,7 +527,7 @@ public:
UString tmp(encoded.size() + 200U); UString tmp(encoded.size() + 200U);
tmp.snprintf("\n\t\tU_INTERNAL_ASSERT_EQUALS(UClientImage_Base::wbuffer->findEndHeader(),false);" tmp.snprintf("\n\t\tU_INTERNAL_ASSERT_EQUALS(UClientImage_Base::wbuffer->findEndHeader(),false)"
"\n\t\tU_http_info.endHeader = %u;" "\n\t\tU_http_info.endHeader = %u;"
"\n\t\t(void) UClientImage_Base::wbuffer->insert(0, \n\tU_CONSTANT_TO_PARAM(%v));\n", n, encoded.rep); "\n\t\t(void) UClientImage_Base::wbuffer->insert(0, \n\tU_CONSTANT_TO_PARAM(%v));\n", n, encoded.rep);
@ -563,7 +563,8 @@ public:
bsighup == false || bsighup == false ||
bfork == false) bfork == false)
{ {
ptr6 = "\n\t\tif (param >= U_DPAGE_FORK) return;\n"; ptr6 = (bfork ? "\n\t\tif (param > U_DPAGE_FORK) return;\n"
: "\n\t\tif (param >= U_DPAGE_FORK) return;\n");
} }
if (bparallelization) ptr7 = "\t\n\t\tif (UServer_Base::startParallelization(UServer_Base::num_client_for_parallelization)) return;\n\t\n"; if (bparallelization) ptr7 = "\t\n\t\tif (UServer_Base::startParallelization(UServer_Base::num_client_for_parallelization)) return;\n\t\n";

View File

@ -27,11 +27,9 @@ public:
# endif # endif
} }
World(const World& w) : id(w.id), randomNumber(w.randomNumber) World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber)
{ {
U_TRACE_REGISTER_OBJECT(5, World, "%p", &w) U_TRACE_REGISTER_OBJECT(5, World, "%u,%u", _id, _randomNumber)
U_MEMORY_TEST_COPY(w)
} }
~World() ~World()

View File

@ -36,8 +36,9 @@ void Url::setService(const char* service, uint32_t n)
if (service_end > 0) (void) url.replace(0, service_end, service, n); if (service_end > 0) (void) url.replace(0, service_end, service, n);
else else
{ {
(void) url.insert(0, U_CONSTANT_TO_PARAM("://")); char buffer[32];
(void) url.insert(0, service, n);
(void) url.insert(0, buffer, u__snprintf(buffer, sizeof(buffer), "%.*s://", n, service));
} }
findpos(); findpos();
@ -49,10 +50,7 @@ UString Url::getUser()
UString usr; UString usr;
if (user_begin < user_end) if (user_begin < user_end) usr = url.substr(user_begin, user_end - user_begin);
{
usr = url.substr(user_begin, user_end - user_begin);
}
U_RETURN_STRING(usr); U_RETURN_STRING(usr);
} }
@ -67,14 +65,12 @@ bool Url::setUser(const char* user, uint32_t n)
if (host_begin < host_end) if (host_begin < host_end)
{ {
if (user_begin < user_end) if (user_begin < user_end) (void) url.replace(user_begin, user_end - user_begin, user, n);
{
(void) url.replace(user_begin, user_end - user_begin, user, n);
}
else else
{ {
(void) url.insert(user_begin, 1, '@'); char buffer[128];
(void) url.insert(user_begin, user, n);
(void) url.insert(user_begin, buffer, u__snprintf(buffer, sizeof(buffer), "%.*s@", n, user));
} }
findpos(); findpos();
@ -199,10 +195,7 @@ void Url::setPath(const char* path, uint32_t n)
if (path_begin < path_end) if (path_begin < path_end)
{ {
if (*path != '/') if (*path != '/') ++path_begin;
{
++path_begin;
}
(void) url.replace(path_begin, path_end - path_begin, path, n); (void) url.replace(path_begin, path_end - path_begin, path, n);
} }
@ -335,7 +328,14 @@ void Url::findpos()
if (service_end < 0) if (service_end < 0)
{ {
service_end = user_begin = user_end = host_begin = host_end = path_begin = path_end = query = 0; service_end =
user_begin =
user_end =
host_begin =
host_end =
path_begin =
path_end =
query = 0;
return; return;
} }

View File

@ -39,8 +39,7 @@ USP_FLAGS="-DAS_cpoll_cppsp_DO" \
--without-ssl --without-pcre --without-expat \ --without-ssl --without-pcre --without-expat \
--without-libz --without-libuuid --without-magic --without-libares \ --without-libz --without-libuuid --without-magic --without-libares \
--enable-static-orm-driver='mysql pgsql sqlite' --enable-static-server-plugin=http \ --enable-static-orm-driver='mysql pgsql sqlite' --enable-static-server-plugin=http \
--with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT" --with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT"
# --enable-debug --enable-HCRS --enable-HPRS --disable-CRPWS --disable-check-time --disable-HIS --disable-log --disable-GSDS --disable-alias --disable-HSTS \
#USP_LIBS="-ljson" \ #USP_LIBS="-ljson" \
cp config.cache .. cp config.cache ..
@ -53,10 +52,11 @@ make clean
make install make install
cd ../../src/ulib/net/server/plugin/usp cd ../../src/ulib/net/server/plugin/usp
make json.la plaintext.la db.la query.la update.la fortune.la rdb.la rquery.la rupdate.la rfortune.la mdb.la mquery.la mupdate.la mfortune.la make json.la plaintext.la db.la query.la update.la fortune.la rdb.la rquery.la rupdate.la rfortune.la mdb.la mquery.la mupdate.la mfortune.la edb.la equery.la eupdate.la
mkdir -p $ULIB_DOCUMENT_ROOT mkdir -p $ULIB_DOCUMENT_ROOT
cp .libs/json.so .libs/plaintext.so \ cp .libs/json.so .libs/plaintext.so \
.libs/edb.so .libs/equery.so .libs/eupdate.so \
.libs/db.so .libs/query.so .libs/update.so .libs/fortune.so \ .libs/db.so .libs/query.so .libs/update.so .libs/fortune.so \
.libs/rdb.so .libs/rquery.so .libs/rupdate.so .libs/rfortune.so \ .libs/rdb.so .libs/rquery.so .libs/rupdate.so .libs/rfortune.so \
.libs/mdb.so .libs/mquery.so .libs/mupdate.so .libs/mfortune.so $ULIB_DOCUMENT_ROOT .libs/mdb.so .libs/mquery.so .libs/mupdate.so .libs/mfortune.so $ULIB_DOCUMENT_ROOT

View File

@ -5,56 +5,45 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static World* pworld;
static UString* jquery;
static char buffer[128]; static char buffer[128];
static UElasticSearchClient* es; static UElasticSearchClient* es;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
static UValue* pvalue; static UValue* pvalue;
#endif #endif
#define QLEN U_CONSTANT_SIZE("{\"query\":{\"match\":{\"_id\":\"") #define QLEN U_CONSTANT_SIZE("{\"query\":{\"match\":{\"_id\":\"")
static void usp_fork_edb() static void usp_fork_edb()
{ {
U_TRACE(5, "::usp_fork_edb()") U_TRACE(5, "::usp_fork_edb()")
U_NEW(UElasticSearchClient, es, UElasticSearchClient); U_NEW(UElasticSearchClient, es, UElasticSearchClient);
if (es->connect() == false) if (es->connect() == false)
{ {
U_WARNING("usp_fork_edb(): connection disabled or failed"); U_WARNING("usp_fork_edb(): connection disabled or failed");
return; return;
} }
U_NEW(World, pworld, World); u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("randomNumber"));
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(OBJECT_VALUE)); U_NEW(UValue, pvalue, UValue(OBJECT_VALUE));
#endif #endif
u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
static void usp_end_edb() static void usp_end_edb()
{ {
U_TRACE(5, "::usp_end_edb()") U_TRACE(5, "::usp_end_edb()")
delete es; delete es;
if (pworld) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue) delete pvalue;
delete jquery; #endif
delete pworld;
# ifndef AS_cpoll_cppsp_DO
delete pvalue;
# endif
}
} }
#endif #endif
--> -->
@ -62,18 +51,18 @@ static void usp_end_edb()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString result; UString result;
(void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, QLEN+u__snprintf(buffer+QLEN, 128, "%u\"}}}", pworld->id = u_get_num_random(10000-1))); (void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, u__snprintf(buffer+QLEN, 128, "%u\"}}}", id = u_get_num_random(10000-1))+QLEN);
(void) UValue::jfind(es->getContent(), *jquery, result); (void) UValue::jfind(es->getContent(), U_CONSTANT_TO_PARAM("randomNumber"), result);
pworld->randomNumber = u_strtoul(result.data(), result.end());
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", pworld->id, result.rep); USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, result.rep);
#else #else
USP_JSON_stringify(*pvalue, World, *pworld); World world(id, u_strtoul(result.data(), result.end()));
USP_JSON_stringify(*pvalue, World, world);
pvalue->clear(); pvalue->clear();
#endif #endif
--> -->

View File

@ -5,9 +5,7 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static UString* jquery;
static char buffer[128]; static char buffer[128];
static World* pworld_query;
static UElasticSearchClient* es; static UElasticSearchClient* es;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
@ -30,15 +28,12 @@ static void usp_fork_equery()
return; return;
} }
U_NEW(World, pworld_query, World); u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("randomNumber"));
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
#endif #endif
u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
@ -48,16 +43,13 @@ static void usp_end_equery()
delete es; delete es;
if (jquery) #ifndef AS_cpoll_cppsp_DO
if (pvalue)
{ {
delete jquery;
delete pworld_query;
# ifndef AS_cpoll_cppsp_DO
delete pvalue; delete pvalue;
delete pvworld_query; delete pvworld_query;
# endif
} }
#endif
} }
#endif #endif
--> -->
@ -65,6 +57,7 @@ static void usp_end_equery()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString rnumber; UString rnumber;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
@ -74,18 +67,18 @@ USP_PUTS_CHAR('[');
while (true) while (true)
{ {
(void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, QLEN+u__snprintf(buffer+QLEN, 128, "%u\"}}}", pworld_query->id = u_get_num_random(10000-1))); (void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, QLEN+u__snprintf(buffer+QLEN, 128, "%u\"}}}", id = u_get_num_random(10000-1)));
(void) UValue::jfind(es->getContent(), *jquery, rnumber); rnumber.clear();
(void) UValue::jfind(es->getContent(), U_CONSTANT_TO_PARAM("randomNumber"), rnumber);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", pworld_query->id, rnumber.rep); USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", id, rnumber.rep);
#else #else
pworld_query->randomNumber = u_strtoul(rnumber.data(), rnumber.end());
World* pworld; World* pworld;
U_NEW(World, pworld, World(*pworld_query)); U_NEW(World, pworld, World(id, u_strtoul(rnumber.data(), rnumber.end())));
pvworld_query->push_back(pworld); pvworld_query->push_back(pworld);
#endif #endif

View File

@ -5,13 +5,14 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static char* pbuffer1;
static char* pbuffer2;
static char buffer1[128]; static char buffer1[128];
static char buffer2[128]; static char buffer2[128];
static World* pworld_update;
static UElasticSearchClient* es; static UElasticSearchClient* es;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
static UValue* pvalue; static UValue* pvalue;
static UVector<World*>* pvworld_update; static UVector<World*>* pvworld_update;
#endif #endif
@ -20,44 +21,45 @@ static UVector<World*>* pvworld_update;
static void usp_fork_eupdate() static void usp_fork_eupdate()
{ {
U_TRACE(5, "::usp_fork_eupdate()") U_TRACE(5, "::usp_fork_eupdate()")
U_NEW(UElasticSearchClient, es, UElasticSearchClient); U_NEW(UElasticSearchClient, es, UElasticSearchClient);
if (es->connect() == false) if (es->connect() == false)
{ {
U_WARNING("usp_fork_eupdate(): connection disabled or failed"); U_WARNING("usp_fork_eupdate(): connection disabled or failed");
return; return;
} }
U_NEW(World, pworld_update, World); u__memcpy(buffer1, "/tfb/world/", ULEN, __PRETTY_FUNCTION__);
pbuffer1 = buffer1 + ULEN;
u__memcpy(buffer2, "{\"doc\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
pbuffer2 = buffer2 + QLEN;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
#endif #endif
u__memcpy(buffer1, "/tfb/world/", ULEN, __PRETTY_FUNCTION__);
u__memcpy(buffer2, "{\"doc\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
static void usp_end_eupdate() static void usp_end_eupdate()
{ {
U_TRACE(5, "::usp_end_eupdate()") U_TRACE(5, "::usp_end_eupdate()")
delete es; delete es;
if (pworld_update) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue)
delete pworld_update; {
delete pvalue;
# ifndef AS_cpoll_cppsp_DO delete pvworld_update;
delete pvalue; }
delete pvworld_update; #endif
# endif
}
} }
#endif #endif
--> -->
@ -65,7 +67,7 @@ static void usp_end_eupdate()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
World* pworld; uint32_t len1, len2, id, rnum;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
@ -73,25 +75,28 @@ USP_PUTS_CHAR('[');
#endif #endif
while (true) while (true)
{ {
(void) es->sendPOST(buffer1, ULEN+u__snprintf(buffer1+ULEN, 128, "%u/_update", pworld_update->id = u_get_num_random(10000-1)), len1 = u__snprintf(pbuffer1, 100, "%u/_update", id = u_get_num_random(10000-1));
buffer2, QLEN+u__snprintf(buffer2+QLEN, 128, "%u\"}}", pworld_update->randomNumber = u_get_num_random(10000-1))); len2 = u__snprintf(pbuffer2, 100, "%u\"}}", rnum = u_get_num_random(10000-1));
(void) es->sendPOST(buffer1, len1+ULEN, buffer2, len2+QLEN);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", pworld_update->id, pworld_update->randomNumber); USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", id, rnum);
#else #else
World* pworld;
U_NEW(World, pworld, World(*pworld_update)); U_NEW(World, pworld, World(id, rnum));
pvworld_update->push_back(pworld); pvworld_update->push_back(pworld);
#endif #endif
if (++i == num_queries) break; if (++i == num_queries) break;
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(','); USP_PUTS_CHAR(',');
#endif #endif
} }
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(']'); USP_PUTS_CHAR(']');

View File

@ -5,58 +5,47 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static World* pworld;
static UString* jquery;
static UMongoDBClient* mc; static UMongoDBClient* mc;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
static UValue* pvalue; static UValue* pvalue;
#endif #endif
static void usp_fork_mdb() static void usp_fork_mdb()
{ {
U_TRACE(5, "::usp_fork_mdb()") U_TRACE(5, "::usp_fork_mdb()")
U_NEW(UMongoDBClient, mc, UMongoDBClient); U_NEW(UMongoDBClient, mc, UMongoDBClient);
if (mc->connect() == false) if (mc->connect() == false)
{ {
U_WARNING("usp_fork_mdb(): connection failed"); U_WARNING("usp_fork_mdb(): connection failed");
return; return;
} }
if (mc->selectCollection("hello_world", "World") == false) if (mc->selectCollection("hello_world", "World") == false)
{ {
U_WARNING("usp_fork_mdb(): selectCollection() failed"); U_WARNING("usp_fork_mdb(): selectCollection() failed");
return; return;
} }
U_NEW(World, pworld, World);
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("{'randomNumber'"));
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(OBJECT_VALUE)); U_NEW(UValue, pvalue, UValue(OBJECT_VALUE));
#endif #endif
} }
#ifdef DEBUG #ifdef DEBUG
static void usp_end_mdb() static void usp_end_mdb()
{ {
U_TRACE(5, "::usp_end_mdb()") U_TRACE(5, "::usp_end_mdb()")
delete mc; delete mc;
if (pworld) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue) delete pvalue;
delete pworld; #endif
delete jquery;
# ifndef AS_cpoll_cppsp_DO
delete pvalue;
# endif
}
} }
#endif #endif
--> -->
@ -64,18 +53,18 @@ static void usp_end_mdb()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString result; UString result;
(void) mc->findOne(pworld->id = u_get_num_random(10000-1)); (void) mc->findOne(id = u_get_num_random(10000-1));
(void) UValue::jread(mc->vitem[0], *jquery, result); // { "_id" : 8980.000000, "id" : 8980.000000, "randomNumber" : 2131.000000 } (void) UValue::jfind(mc->vitem[0], U_CONSTANT_TO_PARAM("randomNumber"), result);
pworld->randomNumber = u_strtoul(result.data(), result.end());
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", pworld->id, result.rep); USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, result.rep);
#else #else
USP_JSON_stringify(*pvalue, World, *pworld); World world(id, u_strtoul(result.data(), result.end()));
USP_JSON_stringify(*pvalue, World, world);
pvalue->clear(); pvalue->clear();
#endif #endif
--> -->

View File

@ -5,7 +5,6 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "fortune.h" #include "fortune.h"
static UString* jquery;
static UString* pencoded; static UString* pencoded;
static UMongoDBClient* mc; static UMongoDBClient* mc;
static Fortune* pfortune2add; static Fortune* pfortune2add;
@ -13,44 +12,42 @@ static UVector<Fortune*>* pvfortune;
static void usp_fork_mfortune() static void usp_fork_mfortune()
{ {
U_TRACE(5, "::usp_fork_mfortune()") U_TRACE(5, "::usp_fork_mfortune()")
U_NEW(UMongoDBClient, mc, UMongoDBClient); U_NEW(UMongoDBClient, mc, UMongoDBClient);
if (mc->connect() == false) if (mc->connect() == false)
{ {
U_WARNING("usp_fork_mfortune(): connection failed"); U_WARNING("usp_fork_mfortune(): connection failed");
return; return;
} }
if (mc->selectCollection("hello_world", "Fortune") == false) if (mc->selectCollection("hello_world", "Fortune") == false)
{ {
U_WARNING("usp_fork_mfortune(): selectCollection() failed"); U_WARNING("usp_fork_mfortune(): selectCollection() failed");
return; return;
} }
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("{'message'")); U_NEW(UString, pencoded, UString(100U));
U_NEW(UString, pencoded, UString(100U)); U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>);
U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>); U_NEW(Fortune, pfortune2add, Fortune(0, U_STRING_FROM_CONSTANT("Additional fortune added at request time.")));
U_NEW(Fortune, pfortune2add, Fortune(0, U_STRING_FROM_CONSTANT("Additional fortune added at request time.")));
} }
#ifdef DEBUG #ifdef DEBUG
static void usp_end_mfortune() static void usp_end_mfortune()
{ {
U_TRACE(5, "::usp_end_mfortune()") U_TRACE(5, "::usp_end_mfortune()")
delete mc; delete mc;
if (jquery) if (pencoded)
{ {
delete jquery; delete pencoded;
delete pencoded; delete pvfortune;
delete pvfortune; delete pfortune2add;
delete pfortune2add; }
}
} }
#endif #endif
--> -->
@ -60,33 +57,37 @@ uint32_t i, n;
UString result; UString result;
U_NEW(Fortune, item, Fortune(*pfortune2add)); U_NEW(Fortune, item, Fortune(*pfortune2add));
pvfortune->push_back(item); pvfortune->push_back(item);
(void) mc->findAll(); (void) mc->findAll();
for (i = 0, n = mc->vitem.size(); i < n; ++i) for (i = 0, n = mc->vitem.size(); i < n; ++i)
{ {
(void) UValue::jread(mc->vitem[i], *jquery, result); // { "_id" : 5.000000, "id" : 5.000000, "message" : "A computer program does what you tell it to do, not what you want it to do." } result.clear();
(void) UValue::jfind(mc->vitem[i], U_CONSTANT_TO_PARAM("message"), result);
U_NEW(Fortune, item, Fortune(i+1, result)); U_NEW(Fortune, item, Fortune(i+1, result));
pvfortune->push_back(item); pvfortune->push_back(item);
} }
pvfortune->sort(Fortune::cmp_obj); pvfortune->sort(Fortune::cmp_obj);
for (i = 0, ++n; i < n; ++i) for (i = 0, ++n; i < n; ++i)
{ {
Fortune* elem = (*pvfortune)[i]; Fortune* elem = (*pvfortune)[i];
UXMLEscape::encode(elem->message, *pencoded); UXMLEscape::encode(elem->message, *pencoded);
USP_PRINTF_ADD( USP_PRINTF_ADD(
"<tr>" "<tr>"
"<td>%u</td>" "<td>%u</td>"
"<td>%v</td>" "<td>%v</td>"
"</tr>", "</tr>",
elem->id, pencoded->rep); elem->id, pencoded->rep);
} }
pvfortune->clear(); pvfortune->clear();
--></table></body></html> --></table></body></html>

View File

@ -5,61 +5,53 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static UString* jquery;
static UMongoDBClient* mc; static UMongoDBClient* mc;
static World* pworld_query;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
static UValue* pvalue; static UValue* pvalue;
static UVector<World*>* pvworld_query; static UVector<World*>* pvworld_query;
#endif #endif
static void usp_fork_mquery() static void usp_fork_mquery()
{ {
U_TRACE(5, "::usp_fork_mquery()") U_TRACE(5, "::usp_fork_mquery()")
U_NEW(UMongoDBClient, mc, UMongoDBClient); U_NEW(UMongoDBClient, mc, UMongoDBClient);
if (mc->connect() == false) if (mc->connect() == false)
{ {
U_WARNING("usp_fork_mquery(): connection disabled or failed"); U_WARNING("usp_fork_mquery(): connection disabled or failed");
return; return;
} }
if (mc->selectCollection("hello_world", "World") == false) if (mc->selectCollection("hello_world", "World") == false)
{ {
U_WARNING("usp_fork_mquery(): selectCollection() failed"); U_WARNING("usp_fork_mquery(): selectCollection() failed");
return; return;
} }
U_NEW(UString, jquery, U_STRING_FROM_CONSTANT("{'randomNumber'"));
U_NEW(World, pworld_query, World);
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
#endif #endif
} }
#ifdef DEBUG #ifdef DEBUG
static void usp_end_mquery() static void usp_end_mquery()
{ {
U_TRACE(5, "::usp_end_mquery()") U_TRACE(5, "::usp_end_mquery()")
delete mc; delete mc;
if (jquery) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue)
delete jquery; {
delete pworld_query; delete pvalue;
delete pvworld_query;
# ifndef AS_cpoll_cppsp_DO }
delete pvalue; #endif
delete pvworld_query;
# endif
}
} }
#endif #endif
--> -->
@ -67,6 +59,7 @@ static void usp_end_mquery()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id;
UString rnumber; UString rnumber;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
@ -75,29 +68,29 @@ USP_PUTS_CHAR('[');
#endif #endif
while (true) while (true)
{ {
(void) mc->findOne(pworld_query->id = u_get_num_random(10000-1)); (void) mc->findOne(id = u_get_num_random(10000-1));
(void) UValue::jread(mc->vitem[0], *jquery, rnumber); // { "_id" : 8980.000000, "id" : 8980.000000, "randomNumber" : 2131.000000 } rnumber.clear();
(void) UValue::jfind(mc->vitem[0], U_CONSTANT_TO_PARAM("randomNumber"), rnumber);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", pworld_query->id, rnumber.rep); USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", id, rnumber.rep);
#else #else
pworld_query->randomNumber = u_strtoul(rnumber.data(), rnumber.end()); World* pworld;
World* pworld; U_NEW(World, pworld, World(id, u_strtoul(rnumber.data(), rnumber.end())));
U_NEW(World, pworld, World(*pworld_query)); pvworld_query->push_back(pworld);
pvworld_query->push_back(pworld);
#endif #endif
if (++i == num_queries) break; if (++i == num_queries) break;
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(','); USP_PUTS_CHAR(',');
#endif #endif
} }
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(']'); USP_PUTS_CHAR(']');

View File

@ -6,57 +6,52 @@ TechEmpower Web Framework Benchmarks
#include "world.h" #include "world.h"
static UMongoDBClient* mc; static UMongoDBClient* mc;
static World* pworld_update;
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
static UValue* pvalue; static UValue* pvalue;
static UVector<World*>* pvworld_update; static UVector<World*>* pvworld_update;
#endif #endif
static void usp_fork_mupdate() static void usp_fork_mupdate()
{ {
U_TRACE(5, "::usp_fork_mupdate()") U_TRACE(5, "::usp_fork_mupdate()")
U_NEW(UMongoDBClient, mc, UMongoDBClient); U_NEW(UMongoDBClient, mc, UMongoDBClient);
if (mc->connect() == false) if (mc->connect() == false)
{ {
U_WARNING("usp_fork_mupdate(): connection disabled or failed"); U_WARNING("usp_fork_mupdate(): connection disabled or failed");
return; return;
} }
if (mc->selectCollection("hello_world", "World") == false) if (mc->selectCollection("hello_world", "World") == false)
{ {
U_WARNING("usp_fork_mupdate(): selectCollection() failed"); U_WARNING("usp_fork_mupdate(): selectCollection() failed");
return; return;
} }
U_NEW(World, pworld_update, World);
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(ARRAY_VALUE)); U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500)); U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
#endif #endif
} }
#ifdef DEBUG #ifdef DEBUG
static void usp_end_mupdate() static void usp_end_mupdate()
{ {
U_TRACE(5, "::usp_end_mupdate()") U_TRACE(5, "::usp_end_mupdate()")
delete mc; delete mc;
if (pworld_update) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue)
delete pworld_update; {
delete pvalue;
# ifndef AS_cpoll_cppsp_DO delete pvworld_update;
delete pvalue; }
delete pvworld_update; #endif
# endif
}
} }
#endif #endif
--> -->
@ -64,6 +59,7 @@ static void usp_end_mupdate()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
uint32_t id, rnum;
int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500); int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
@ -71,28 +67,26 @@ USP_PUTS_CHAR('[');
#endif #endif
while (true) while (true)
{ {
(void) mc->findOne(pworld_update->id = u_get_num_random(10000-1)); (void) mc->findOne( id = u_get_num_random(10000-1));
(void) mc->update(id, "randomNumber", rnum = u_get_num_random(10000-1));
(void) mc->update(pworld_update->id, "randomNumber", pworld_update->randomNumber = u_get_num_random(10000-1));
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", pworld_update->id, pworld_update->randomNumber); USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", id, rnum);
#else #else
World* pworld;
World* pworld; U_NEW(World, pworld, World(id, rnum));
U_NEW(World, pworld, World(*pworld_update)); pvworld_update->push_back(pworld);
pvworld_update->push_back(pworld);
#endif #endif
if (++i == num_queries) break; if (++i == num_queries) break;
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(','); USP_PUTS_CHAR(',');
#endif #endif
} }
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(']'); USP_PUTS_CHAR(']');

View File

@ -5,7 +5,6 @@ TechEmpower Web Framework Benchmarks
<!--#declaration <!--#declaration
#include "world.h" #include "world.h"
static World* pworld;
static char buffer[128]; static char buffer[128];
static UREDISClient_Base* rc; static UREDISClient_Base* rc;
@ -26,13 +25,11 @@ static void usp_fork_rdb()
return; return;
} }
U_NEW(World, pworld, World); u__memcpy(buffer, "world:", U_CONSTANT_SIZE("world:"), __PRETTY_FUNCTION__);
#ifndef AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO
U_NEW(UValue, pvalue, UValue(OBJECT_VALUE)); U_NEW(UValue, pvalue, UValue(OBJECT_VALUE));
#endif #endif
u__memcpy(buffer, "world:", U_CONSTANT_SIZE("world:"), __PRETTY_FUNCTION__);
} }
#ifdef DEBUG #ifdef DEBUG
@ -42,14 +39,9 @@ static void usp_end_rdb()
delete rc; delete rc;
if (pworld) #ifndef AS_cpoll_cppsp_DO
{ if (pvalue) delete pvalue;
delete pworld; #endif
# ifndef AS_cpoll_cppsp_DO
delete pvalue;
# endif
}
} }
#endif #endif
--> -->
@ -57,18 +49,16 @@ static void usp_end_rdb()
Content-Type: application/json Content-Type: application/json
--> -->
<!--#code <!--#code
UStringRep* rep; uint32_t id;
(void) rc->get(buffer, 6+u_num2str32(buffer+6, pworld->id = u_get_num_random(10000-1))); (void) rc->get(buffer, 6+u_num2str32(buffer+6, id = u_get_num_random(10000-1)));
rep = rc->vitem[0].rep;
pworld->randomNumber = u_strtoul(rep->data(), rep->end());
#ifdef AS_cpoll_cppsp_DO #ifdef AS_cpoll_cppsp_DO
USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", pworld->id, rep); USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, rc->vitem[0].rep);
#else #else
USP_JSON_stringify(*pvalue, World, *pworld); UStringRep* rep = rc->vitem[0].rep;
World world(id, u_strtoul(rep->data(), rep->end()));
USP_JSON_stringify(*pvalue, World, world);
pvalue->clear(); pvalue->clear();
#endif #endif
--> -->

View File

@ -27,11 +27,9 @@ public:
# endif # endif
} }
World(const World& w) : id(w.id), randomNumber(w.randomNumber) World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber)
{ {
U_TRACE_REGISTER_OBJECT(5, World, "%p", &w) U_TRACE_REGISTER_OBJECT(5, World, "%u,%u", _id, _randomNumber)
U_MEMORY_TEST_COPY(w)
} }
~World() ~World()