1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
This commit is contained in:
stefanocasazza 2017-12-14 16:48:16 +01:00
parent eeac9aca71
commit 120253d566
13 changed files with 173 additions and 100 deletions

View File

@ -361,11 +361,13 @@ public:
* consumption, but may be usefull to support feature such as RPC where bandwith is limited
*/
static uint32_t size_output;
UString output() const
{
U_TRACE_NO_PARAM(0, "UValue::output()")
UString result(U_max(size+100U,U_CAPACITY));
UString result(U_max(size_output+100U,U_CAPACITY));
pstringify = result.data(); // buffer to stringify json
@ -380,7 +382,7 @@ public:
{
U_TRACE_NO_PARAM(0, "UValue::prettify()")
UString result(size*2+800U);
UString result(size_output*2+800U);
pstringify = result.data(); // buffer to stringify json
@ -397,7 +399,7 @@ public:
{
U_TRACE(0, "UValue::stringify(%V,%p)", result.rep, &json)
(void) result.reserve(json.size+100U);
(void) result.reserve(U_max(json.size_output+100U,U_CAPACITY));
pstringify = result.pend(); // buffer to stringify json
@ -607,7 +609,6 @@ protected:
union jval pkey, // only if binded to an object
value;
static uint32_t size;
static UFlatBuffer* pfb;
static char* pstringify; // buffer to stringify json
@ -1211,7 +1212,7 @@ public:
{
U_TRACE(0, "UJsonTypeHandler<T>::toJSON(%V)", json.rep)
json.push_back('{');
json.__push('{');
((T*)pval)->toJSON(json);
@ -1266,6 +1267,8 @@ template <class T> void JSON_OBJ_stringify(UString& str, T& obj)
{
U_TRACE(0, "JSON_OBJ_stringify(%V,%p)", str.rep, &obj)
(void) str.reserve(U_max(UValue::size_output+100U,U_CAPACITY));
UJsonTypeHandler<T>(obj).toJSON(str);
U_INTERNAL_DUMP("str(%u) = %V", str.size(), str.rep)
@ -1301,7 +1304,11 @@ public:
{
U_TRACE(0, "UJsonTypeHandler<null>::toJSON(%V)", json.rep)
(void) json.append(U_CONSTANT_TO_PARAM("null"));
char* ptr = json.pend();
u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('n','u','l','l'));
json.rep->_length += 4;
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
}
@ -1338,7 +1345,22 @@ public:
{
U_TRACE(0, "UJsonTypeHandler<bool>::toJSON(%V)", json.rep)
(void) json.append(*(*(bool*)pval ? UString::str_true : UString::str_false));
char* ptr = json.pend();
if (*(bool*)pval)
{
u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('t','r','u','e'));
json.rep->_length += 4;
}
else
{
u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('f','a','l','s'));
ptr[4] = 'e';
json.rep->_length += 5;
}
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
}
@ -1375,7 +1397,7 @@ public:
{
U_TRACE(0, "UJsonTypeHandler<char>::toJSON(%V)", json.rep)
json.push_back(*(char*)pval);
json.__push(*(char*)pval);
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
}
@ -1412,7 +1434,7 @@ public:
{
U_TRACE(0, "UJsonTypeHandler<unsigned char>::toJSON(%V)", json.rep)
json.push_back(*(unsigned char*)pval);
json.__push(*(unsigned char*)pval);
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
}
@ -1956,7 +1978,7 @@ public:
uvector* pvec = (uvector*)pval;
json.push_back('[');
json.__push('[');
if (pvec->_length)
{
@ -1969,11 +1991,11 @@ public:
if (++ptr >= end) break;
json.push_back(',');
json.__push(',');
}
}
json.push_back(']');
json.__push(']');
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
}
@ -2045,7 +2067,7 @@ public:
uvectorbase* pvec = (uvectorbase*)pval;
json.push_back('[');
json.__push('[');
if (pvec->_length)
{
@ -2058,11 +2080,11 @@ public:
if (++ptr >= end) break;
json.push_back(',');
json.__push(',');
}
}
json.push_back(']');
json.__push(']');
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
}
@ -2132,10 +2154,17 @@ public:
uhashmap* pmap = (uhashmap*)pval;
if (pmap->empty()) (void) json.append(U_CONSTANT_TO_PARAM("{}"));
if (pmap->empty())
{
char* ptr = json.pend();
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16('{','}'));
json.rep->_length += 2;
}
else
{
json.push_back('{');
json.__push('{');
# ifndef HAVE_OLD_IOSTREAM
do { json.toJSON<T>(pmap->getKey(), UJsonTypeHandler<T>(*(pmap->elem()))); } while (pmap->next());
@ -2217,7 +2246,7 @@ public:
if (pmap->first())
{
json.push_back('{');
json.__push('{');
do { json.toJSON<UStringRep>(pmap->getKey(), UJsonTypeHandler<UStringRep>(*(UStringRep*)(pmap->elem()))); } while (pmap->next());
@ -2225,7 +2254,11 @@ public:
}
else
{
(void) json.append(U_CONSTANT_TO_PARAM("{}"));
char* ptr = json.pend();
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16('{','}'));
json.rep->_length += 2;
}
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
@ -2306,7 +2339,7 @@ public:
stdvector* pvec = (stdvector*)pval;
uint32_t i = 0, n = pvec->size();
json.push_back('[');
json.__push('[');
while (true)
{
@ -2314,10 +2347,10 @@ public:
if (++i >= n) break;
json.push_back(',');
json.__push(',');
}
json.push_back(']');
json.__push(']');
U_INTERNAL_DUMP("json(%u) = %V", json.size(), json.rep)
}
@ -2391,10 +2424,17 @@ public:
stringtobitmaskmap* pmap = (stringtobitmaskmap*)pval;
if (pmap->empty()) (void) json.append(U_CONSTANT_TO_PARAM("{}"));
if (pmap->empty())
{
char* ptr = json.pend();
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16('{','}'));
json.rep->_length += 2;
}
else
{
json.push_back('{');
json.__push('{');
// this is is C++17 vvv
for (const auto & [ key, value ] : *pmap) json.toJSON<T>(key, UJsonTypeHandler<T>(value));

View File

@ -337,7 +337,12 @@ protected:
}
private:
UFlatBufferValue() {}
UFlatBufferValue()
{
// coverity[uninit_ctor]
# ifdef U_COVERITY_FALSE_POSITIVE
# endif
}
friend class UFlatBuffer;
@ -360,6 +365,9 @@ public:
// coverity[uninit_ctor]
# ifdef U_COVERITY_FALSE_POSITIVE
u_ = 0ULL;
type_ =
min_bit_width_ = BIT_WIDTH_8;
reset();
# endif
}

View File

@ -327,7 +327,7 @@ private:
# endif
# if U_USE_ALPN
U_SYSCALL_VOID(SSL_CTX_set_alpn_select_cb, "%p,%p,%p", ctx, selectProto, 0); // ALPN selection callback
U_SYSCALL_VOID(SSL_CTX_set_alpn_select_cb, "%p,%p,%p", ctx, selectProto, U_NULLPTR); // ALPN selection callback
# endif
}
#endif

View File

@ -2234,10 +2234,9 @@ public:
U_ASSERT_MAJOR(space(), 12)
uint32_t sz = size();
char* ptr = c_pointer(sz);
char* ptr = pend();
rep->_length = sz + u_num2str32(number, ptr) - ptr;
rep->_length += u_num2str32(number, ptr) - ptr;
U_INTERNAL_ASSERT(invariant())
}
@ -2248,10 +2247,9 @@ public:
U_ASSERT_MAJOR(space(), 12)
uint32_t sz = size();
char* ptr = c_pointer(sz);
char* ptr = pend();
rep->_length = sz + u_num2str32s(number, ptr) - ptr;
rep->_length += u_num2str32s(number, ptr) - ptr;
U_INTERNAL_ASSERT(invariant())
}
@ -2262,10 +2260,9 @@ public:
U_ASSERT_MAJOR(space(), 22)
uint32_t sz = size();
char* ptr = c_pointer(sz);
char* ptr = pend();
rep->_length = sz + u_num2str64(number, ptr) - ptr;
rep->_length += u_num2str64(number, ptr) - ptr;
U_INTERNAL_ASSERT(invariant())
}
@ -2276,10 +2273,9 @@ public:
U_ASSERT_MAJOR(space(), 22)
uint32_t sz = size();
char* ptr = c_pointer(sz);
char* ptr = pend();
rep->_length = sz + u_num2str64s(number, ptr) - ptr;
rep->_length += u_num2str64s(number, ptr) - ptr;
U_INTERNAL_ASSERT(invariant())
}
@ -2288,12 +2284,11 @@ public:
{
U_TRACE(0, "UString::appendNumberDouble(%g)", number)
U_ASSERT_MAJOR(space(), 32)
U_ASSERT_MAJOR(space(), 22)
uint32_t sz = size();
char* ptr = c_pointer(sz);
char* ptr = pend();
rep->_length = sz + u_dtoa(number, ptr) - ptr;
rep->_length += u_dtoa(number, ptr) - ptr;
U_INTERNAL_ASSERT(invariant())
}
@ -2304,12 +2299,11 @@ public:
U_ASSERT_MAJOR(space(), tlen)
uint32_t sz = size();
char* ptr = c_pointer(sz);
char* ptr = pend();
U_MEMCPY(ptr, t, tlen);
rep->_length = sz + tlen;
rep->_length += tlen;
U_INTERNAL_ASSERT(invariant())
}
@ -2318,9 +2312,10 @@ public:
{
U_TRACE(0, "UString::appendDataQuoted(%.*S,%u)", tlen, t, tlen)
U_ASSERT_MAJOR(space(), tlen+2)
U_INTERNAL_ASSERT_EQUALS(u_is_quoted(t, tlen), false)
char* ptr = __append(U_CONSTANT_SIZE("\"\"") + tlen);
char* ptr = pend();
*ptr++ = '"';
@ -2328,6 +2323,8 @@ public:
ptr[tlen] = '"';
rep->_length += tlen+2;
U_INTERNAL_ASSERT(invariant())
}
@ -2413,32 +2410,48 @@ public:
{
U_TRACE(0, "UString::toJSON<T>(%.*S,%u,%p)", sz, name, sz, &member)
U_ASSERT_MAJOR(space(), sz+6)
U_INTERNAL_ASSERT_MAJOR(sz, 0)
U_INTERNAL_ASSERT(u_is_quoted(name, sz))
(void) append(name, sz);
char* ptr = pend();
push_back(':');
U_MEMCPY(ptr, name, sz);
ptr[sz] = ':';
rep->_length += sz+1;
member.toJSON(*this);
push_back(',');
U_INTERNAL_ASSERT(invariant())
__push(',');
}
template <typename T> void toJSON(const UString& name, UJsonTypeHandler<T> member)
{
U_TRACE(0, "UString::toJSON<T>(%V,%p)", name.rep, &member)
appendDataQuoted(U_STRING_TO_PARAM(name));
uint32_t tlen = name.size();
const char* t = name.data();
push_back(':');
U_ASSERT_MAJOR(space(), tlen+6)
U_INTERNAL_ASSERT_MAJOR(tlen, 0)
U_INTERNAL_ASSERT_EQUALS(u_is_quoted(t, tlen), false)
char* ptr = pend();
*ptr++ = '"';
U_MEMCPY(ptr, t, tlen);
ptr += tlen;
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16('"',':'));
rep->_length += tlen+3;
member.toJSON(*this);
push_back(',');
U_INTERNAL_ASSERT(invariant())
__push(',');
}
// -----------------------------------------------------------------------------------------------------------------------
@ -2449,6 +2462,19 @@ private:
char* __append(uint32_t n);
char* __replace(uint32_t pos, uint32_t n1, uint32_t n2);
void __push(uint8_t c)
{
U_TRACE(0, "UString::__push(%u)", c)
U_ASSERT_MAJOR(space(), 1)
uint8_t* ptr = (uint8_t*)(rep->str + rep->_length++);
*ptr = c;
U_INTERNAL_ASSERT(invariant())
}
template <class T> friend class UJsonTypeHandler;
};

View File

@ -136,7 +136,7 @@ public:
{
U_TRACE(0+256, "UHTTP2::Connection::preallocate(%u)", max_connection)
U_INTERNAL_ASSERT_EQUALS(vConnection, 0)
U_INTERNAL_ASSERT_EQUALS(vConnection, U_NULLPTR)
U_INTERNAL_DUMP("sizeof(Connection) = %u sizeof(Stream) = %u", sizeof(Connection), sizeof(Stream))
@ -665,7 +665,7 @@ protected:
entry->value->release();
entry->name =
entry->value = 0;
entry->value = U_NULLPTR;
}
static void evictHpackDynTblFirstEntry(HpackDynamicTable* dyntbl)

View File

@ -1275,9 +1275,9 @@ private:
}
#ifdef U_HTTP2_DISABLE
static UString getHeaderFromCache(uint32_t idx) { return getDataFromCache(file_data->array, idx); }
static UString getHeaderFromCache(uint32_t idx) { return getDataFromCache(file_data->array, idx); }
#else
static UString getHeaderFromCache(uint32_t idx) { return getDataFromCache((U_http_version != '2' ? file_data->array : (idx /= 2, file_data->http2)), idx); }
static UString getHeaderFromCache(uint32_t idx) { return (U_http_version != '2' ? getDataFromCache(file_data->array, idx) : getDataFromCache(file_data->http2, idx / 2)); }
#endif
static UString getBodyFromCache() { return getDataFromCache(file_data->array, 0); }

View File

@ -18,7 +18,7 @@
int UValue::pos;
int UValue::jsonParseFlags;
char* UValue::pstringify;
uint32_t UValue::size;
uint32_t UValue::size_output;
UValue::jval UValue::o;
UFlatBuffer* UValue::pfb;
UValue::parser_stack_data UValue::sd[U_JSON_PARSE_STACK_SIZE];
@ -994,13 +994,13 @@ void UValue::toFlatBuffer(UFlatBuffer& fb, UString& result) const
{
U_TRACE(0, "UValue::toFlatBuffer(%p,%p)", &fb, &result)
U_INTERNAL_DUMP("size = %u UFlatBuffer::getBufferMax() = %u UFlatBuffer::getStackMax() = %u", size, UFlatBuffer::getBufferMax(), UFlatBuffer::getStackMax())
U_INTERNAL_DUMP("size_output = %u UFlatBuffer::getBufferMax() = %u UFlatBuffer::getStackMax() = %u", size_output, UFlatBuffer::getBufferMax(), UFlatBuffer::getStackMax())
uint8_t* prev_stack;
uint8_t* prev_buffer;
uint8_t stack[64 * 1024];
uint32_t end, prev_stack_size, prev_buffer_size;
bool breset1 = (size > UFlatBuffer::getBufferMax()),
bool breset1 = (size_output > UFlatBuffer::getBufferMax()),
breset2 = (sizeof(stack) > UFlatBuffer::getStackMax());
// buffer to serialize json
@ -1011,14 +1011,14 @@ void UValue::toFlatBuffer(UFlatBuffer& fb, UString& result) const
prev_buffer = UFlatBuffer::getBuffer();
prev_buffer_size = UFlatBuffer::getBufferMax();
(void) result.reserve(size+100U);
(void) result.reserve(U_max(size_output+100U,U_CAPACITY));
UFlatBuffer::setBuffer((uint8_t*)(pstringify = result.data()), result.capacity());
}
if (breset2)
{
U_INTERNAL_ASSERT_MINOR(size, sizeof(stack))
U_INTERNAL_ASSERT_MINOR(size_output, sizeof(stack))
prev_stack = UFlatBuffer::getStack();
prev_stack_size = UFlatBuffer::getStackMax();
@ -1160,7 +1160,7 @@ bool UValue::parse(const UString& document)
const char* start;
uint64_t integerPart;
const char* s = document.data();
const char* end = s + (size = document.size());
const char* end = s + (size_output = document.size());
uint32_t sz, significandDigit, decimalDigit, exponent;
bool minus = false, colon = false, comma = false, separator = true;

View File

@ -619,20 +619,23 @@ loop2: if (pevents->events)
{
handler_event = (UEventFd*)pevents->data.ptr;
U_INTERNAL_DUMP("i = %d handler_event->fd = %d ", i, handler_event->fd)
U_INTERNAL_DUMP("i = %d handler_event->fd = %d", i, handler_event->fd)
U_INTERNAL_ASSERT_DIFFERS(handler_event->fd, -1)
// U_INTERNAL_ASSERT_DIFFERS(handler_event->fd, -1)
if (handler_event->handlerRead() == U_NOTIFIER_DELETE)
if (handler_event->fd != -1)
{
handlerDelete(handler_event);
if (handler_event->handlerRead() == U_NOTIFIER_DELETE)
{
handlerDelete(handler_event);
pevents->events = 0;
}
else
{
if (U_ClientImage_state != U_PLUGIN_HANDLER_AGAIN) bloop1 = true;
else pevents->events = 0;
pevents->events = 0;
}
else
{
if (U_ClientImage_state != U_PLUGIN_HANDLER_AGAIN) bloop1 = true;
else pevents->events = 0;
}
}
}

View File

@ -3250,7 +3250,7 @@ bool UHTTP2::initRequest()
pConnection->itable.clear(); // NB: we can't clear it before because UClientImage_Base::getRequestUri() depend on it...
pConnection->state = CONN_STATE_OPEN;
pConnection->bug_client = 0;
pConnection->bug_client = U_NULLPTR;
U_RETURN(false);
}
@ -3877,7 +3877,7 @@ void UHTTP2::clearHpackDynTbl(HpackDynamicTable* dyntbl)
dyntbl->entry_capacity =
dyntbl->entry_start_index =
dyntbl->hpack_size = 0;
dyntbl->entries = 0;
dyntbl->entries = U_NULLPTR;
U_INTERNAL_DUMP("num_entries = %u entry_capacity = %u entry_start_index = %u hpack_size = %u hpack_capacity = %u hpack_max_capacity = %u",
dyntbl->num_entries, dyntbl->entry_capacity, dyntbl->entry_start_index, dyntbl->hpack_size, dyntbl->hpack_capacity, dyntbl->hpack_max_capacity)

View File

@ -2223,7 +2223,7 @@ const char* UHTTP::getHeaderValuePtr(const char* name, uint32_t name_len, bool n
*UClientImage_Base::request = UHTTP2::pConnection->itable.at(name, name_len);
return (*UClientImage_Base::request ? UClientImage_Base::request->data() : (const char*)0);
return (*UClientImage_Base::request ? UClientImage_Base::request->data() : (const char*)U_NULLPTR);
}
return getHeaderValuePtr(*UClientImage_Base::request, name, name_len, nocase);

View File

@ -4,7 +4,8 @@
(cd benchmark; rm -f db; creat_link FrameworkBenchmarks/ULib/db db)
DOC_ROOT=sse_example
DOC_ROOT=docroot
#DOC_ROOT=sse_example
#DOC_ROOT=ruby/blog
#DOC_ROOT=benchmark/docroot
@ -77,25 +78,19 @@ userver {
#PLUGIN "ssi http"
#ORM_DRIVER "sqlite mysql"
#ORM_DRIVER sqlite
DOCUMENT_ROOT sse_example
PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs
ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs
#DOCUMENT_ROOT docroot
#PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs
#ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs
#DOCUMENT_ROOT JONATHAN/docroot
#DOCUMENT_ROOT benchmark/docroot
#PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs
#ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs
#DOCUMENT_ROOT .
#PLUGIN_DIR ../../src/ulib/net/server/plugin/.libs
#ORM_DRIVER_DIR ../../src/ulib/orm/driver/.libs
#DOCUMENT_ROOT php
#PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs
#ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs
DOCUMENT_ROOT docroot
#DOCUMENT_ROOT sse_example
PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs
ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs
#DOCUMENT_ROOT JONATHAN/docroot
#DOCUMENT_ROOT benchmark/docroot
#DOCUMENT_ROOT ruby/blog/public
#PLUGIN_DIR ../../../../../src/ulib/net/server/plugin/.libs
#ORM_DRIVER_DIR ../../../../../src/ulib/orm/driver/.libs
#PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs
#ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs
}
http {
#ALIAS "[ / /100.html ]"

View File

@ -70,8 +70,9 @@ start_prg_background userver_tcp -c inp/webserver.cfg
wait_server_ready localhost 8080
#ab -k -n 2 -c 2 http://$ADDRESS:8080/servlet/benchmarking?name=stefano >/dev/null 2>&1
ab -k -n 100 -c 2 http://127.0.0.1:8080/servlet/benchmarking?name=stefano >/dev/null 2>&1
#ab -k -n 2 -c 2 "http://$ADDRESS:8080/servlet/benchmarking?name=stefano" >/dev/null 2>&1
ab -k -n 100 -c 2 'http://127.0.0.1:8080/servlet/benchmarking?name=stefano' >/dev/null 2>&1
#ab -k -n 100000 -c 1000 'http://127.0.0.1:8080/servlet/benchmarking?name=stefano' >/tmp/ab.txt 2>&1
$SLEEP
kill_server userver_tcp

View File

@ -4,11 +4,11 @@ Four Debian releases are available on the main site:
Debian 7.11, or wheezy. Access this release through dists/oldoldstable
Debian 7.11 was released Saturday, 4th June 2016.
Debian 8.9, or jessie. Access this release through dists/oldstable
Debian 8.9 was released Saturday, 22nd July 2017.
Debian 8.10, or jessie. Access this release through dists/oldstable
Debian 8.10 was released Saturday, 9th December 2017.
Debian 9.2, or stretch. Access this release through dists/stable
Debian 9.2 was released Saturday, 7th October 2017.
Debian 9.3, or stretch. Access this release through dists/stable
Debian 9.3 was released Saturday, 9th December 2017.
Testing, or buster. Access this release through dists/testing. The
current tested development snapshot is named buster. Packages which