|
@@ -10,351 +10,378 @@
|
|
#include <ulib/net/server/client_image.h>
|
|
#include <ulib/net/server/client_image.h>
|
|
|
|
|
|
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
|
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
|
|
|
+# include <ulib/event/event_db.h>
|
|
# include <ulib/orm/driver/orm_driver_pgsql.h>
|
|
# include <ulib/orm/driver/orm_driver_pgsql.h>
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-class World {
|
|
|
|
|
|
+class U_EXPORT World {
|
|
public:
|
|
public:
|
|
- uint32_t id, randomNumber;
|
|
|
|
|
|
+ uint32_t id, randomNumber;
|
|
|
|
|
|
- World()
|
|
|
|
- {
|
|
|
|
- U_TRACE_CTOR(5, World, "")
|
|
|
|
|
|
+ World()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_CTOR(5, World, "")
|
|
|
|
|
|
- // coverity[uninit_ctor]
|
|
|
|
-# ifdef U_COVERITY_FALSE_POSITIVE
|
|
|
|
- id = randomNumber = 0;
|
|
|
|
-# endif
|
|
|
|
- }
|
|
|
|
|
|
+ // coverity[uninit_ctor]
|
|
|
|
+# ifdef U_COVERITY_FALSE_POSITIVE
|
|
|
|
+ id = randomNumber = 0;
|
|
|
|
+# endif
|
|
|
|
+ }
|
|
|
|
|
|
- World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber)
|
|
|
|
- {
|
|
|
|
- U_TRACE_CTOR(5, World, "%u,%u", _id, _randomNumber)
|
|
|
|
- }
|
|
|
|
|
|
+ World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_CTOR(5, World, "%u,%u", _id, _randomNumber)
|
|
|
|
+ }
|
|
|
|
|
|
- World(const World& w) : id(w.id), randomNumber(w.randomNumber)
|
|
|
|
- {
|
|
|
|
- U_TRACE_CTOR(5, World, "%p", &w)
|
|
|
|
|
|
+ World(const World& w) : id(w.id), randomNumber(w.randomNumber)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_CTOR(5, World, "%p", &w)
|
|
|
|
|
|
- U_MEMORY_TEST_COPY(w)
|
|
|
|
- }
|
|
|
|
|
|
+ U_MEMORY_TEST_COPY(w)
|
|
|
|
+ }
|
|
|
|
|
|
- ~World()
|
|
|
|
- {
|
|
|
|
- U_TRACE_DTOR(5, World)
|
|
|
|
- }
|
|
|
|
|
|
+ ~World()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_DTOR(5, World)
|
|
|
|
+ }
|
|
|
|
|
|
- // JSON
|
|
|
|
|
|
+ // JSON
|
|
|
|
|
|
- void toJSON(UString& json)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::toJSON(%V)", json.rep)
|
|
|
|
|
|
+ void toJSON(UString& json)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::toJSON(%V)", json.rep)
|
|
|
|
|
|
- json.toJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
|
|
|
|
- json.toJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
|
|
|
|
- }
|
|
|
|
|
|
+ json.toJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
|
|
|
|
+ json.toJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
|
|
|
|
+ }
|
|
|
|
|
|
- void fromJSON(UValue& json)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::fromJSON(%p)", &json)
|
|
|
|
|
|
+ void fromJSON(UValue& json)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::fromJSON(%p)", &json)
|
|
|
|
|
|
- json.fromJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
|
|
|
|
- json.fromJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
|
|
|
|
- }
|
|
|
|
|
|
+ json.fromJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
|
|
|
|
+ json.fromJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
|
|
|
|
+ }
|
|
|
|
|
|
- // ORM
|
|
|
|
|
|
+ // ORM
|
|
|
|
|
|
- void bindParam(UOrmStatement* stmt)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::bindParam(%p)", stmt)
|
|
|
|
|
|
+ void bindParam(UOrmStatement* stmt)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::bindParam(%p)", stmt)
|
|
|
|
|
|
- stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int));
|
|
|
|
- stmt->bindParam(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
|
|
|
|
- }
|
|
|
|
|
|
+ stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int));
|
|
|
|
+ stmt->bindParam(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
|
|
|
|
+ }
|
|
|
|
|
|
- void bindResult(UOrmStatement* stmt)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::bindResult(%p)", stmt)
|
|
|
|
|
|
+ void bindResult(UOrmStatement* stmt)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::bindResult(%p)", stmt)
|
|
|
|
|
|
- stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int));
|
|
|
|
- stmt->bindResult(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
|
|
|
|
- }
|
|
|
|
|
|
+ stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int));
|
|
|
|
+ stmt->bindResult(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
|
|
|
|
+ }
|
|
|
|
|
|
- // SERVICE
|
|
|
|
|
|
+ // SERVICE
|
|
|
|
|
|
- bool operator<(const World& other) const { return cmp_obj(&id, &other.id); }
|
|
|
|
|
|
+ bool operator<(const World& other) const { return cmp_obj(&id, &other.id); }
|
|
|
|
|
|
- static int cmp_obj(const void* a, const void* b)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::cmp_obj(%p,%p)", a, b)
|
|
|
|
|
|
+ static int cmp_obj(const void* a, const void* b)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::cmp_obj(%p,%p)", a, b)
|
|
|
|
|
|
-# ifdef U_STDCPP_ENABLE
|
|
|
|
- /**
|
|
|
|
- * The comparison function must follow a strict-weak-ordering
|
|
|
|
- *
|
|
|
|
- * 1) For all x, it is not the case that x < x (irreflexivity)
|
|
|
|
- * 2) For all x, y, if x < y then it is not the case that y < x (asymmetry)
|
|
|
|
- * 3) For all x, y, and z, if x < y and y < z then x < z (transitivity)
|
|
|
|
- * 4) For all x, y, and z, if x is incomparable with y, and y is incomparable with z, then x is incomparable with z (transitivity of incomparability)
|
|
|
|
- */
|
|
|
|
|
|
+# ifdef U_STDCPP_ENABLE
|
|
|
|
+ /**
|
|
|
|
+ * The comparison function must follow a strict-weak-ordering
|
|
|
|
+ *
|
|
|
|
+ * 1) For all x, it is not the case that x < x (irreflexivity)
|
|
|
|
+ * 2) For all x, y, if x < y then it is not the case that y < x (asymmetry)
|
|
|
|
+ * 3) For all x, y, and z, if x < y and y < z then x < z (transitivity)
|
|
|
|
+ * 4) For all x, y, and z, if x is incomparable with y, and y is incomparable with z, then x is incomparable with z (transitivity of incomparability)
|
|
|
|
+ */
|
|
|
|
|
|
- return (((const World*)a)->id < (((const World*)b)->id));
|
|
|
|
-# else
|
|
|
|
- return (*(const World**)a)->id < ((*(const World**)b)->id);
|
|
|
|
-# endif
|
|
|
|
- }
|
|
|
|
|
|
+ return (((const World*)a)->id < (((const World*)b)->id));
|
|
|
|
+# else
|
|
|
|
+ return (*(const World**)a)->id < ((*(const World**)b)->id);
|
|
|
|
+# endif
|
|
|
|
+ }
|
|
|
|
|
|
- static char* pwbuffer;
|
|
|
|
- static char wbuffer[18000];
|
|
|
|
- static uint32_t rnum, rnumber[500];
|
|
|
|
|
|
+ static char* ptr;
|
|
|
|
+ static char* pwbuffer;
|
|
|
|
+ static char wbuffer[18000];
|
|
|
|
+ static uint32_t rnum, rnumber[501];
|
|
|
|
|
|
- static World* pworld_query;
|
|
|
|
- static UOrmSession* psql_query;
|
|
|
|
- static UOrmStatement* pstmt_query;
|
|
|
|
|
|
+ static World* pworld_query;
|
|
|
|
+ static UOrmSession* psql_query;
|
|
|
|
+ static UOrmStatement* pstmt_query;
|
|
|
|
|
|
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
|
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
|
- static PGconn* conn;
|
|
|
|
- static UOrmDriverPgSql* pdrv;
|
|
|
|
- static UPgSqlStatement* pstmt;
|
|
|
|
- static char num2str[sizeof(unsigned int)];
|
|
|
|
|
|
+ static PGconn* conn;
|
|
|
|
+ static UPgSqlStatement* pstmt;
|
|
|
|
+ static char num2str[sizeof(unsigned int)];
|
|
|
|
|
|
- static bool initPipeline()
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::initPipeline()")
|
|
|
|
|
|
+ static PGresult* execPrepared()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::execPrepared()")
|
|
|
|
|
|
- if (pdrv)
|
|
|
|
- {
|
|
|
|
- (void) U_SYSCALL(PQsetnonblocking, "%p,%u", conn, 1);
|
|
|
|
- (void) U_SYSCALL(PQenterBatchMode, "%p", conn);
|
|
|
|
|
|
+ U_INTERNAL_ASSERT_MAJOR(rnumber[0], 0)
|
|
|
|
|
|
- U_RETURN(true);
|
|
|
|
- }
|
|
|
|
|
|
+ *(unsigned int*)num2str = htonl(rnumber[0]);
|
|
|
|
|
|
- U_RETURN(false);
|
|
|
|
- }
|
|
|
|
|
|
+ PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
|
|
|
|
|
|
- static PGresult* execPrepared()
|
|
|
|
- {
|
|
|
|
- U_TRACE_NO_PARAM(5, "World::execPrepared()")
|
|
|
|
|
|
+ U_RETURN_POINTER(res, PGresult);
|
|
|
|
+ }
|
|
|
|
|
|
- U_INTERNAL_ASSERT_MAJOR(rnumber[0], 0)
|
|
|
|
|
|
+ static PGresult* execPrepared(uint32_t i)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::execPrepared(%u)", i)
|
|
|
|
|
|
- *(unsigned int*)num2str = htonl(rnumber[0]);
|
|
|
|
|
|
+ U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
|
|
|
|
|
|
- PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
|
|
|
|
|
|
+ *(unsigned int*)num2str = htonl(rnumber[i]);
|
|
|
|
|
|
- U_RETURN_POINTER(res, PGresult);
|
|
|
|
- }
|
|
|
|
|
|
+ PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
|
|
|
|
|
|
- static PGresult* execPrepared(uint32_t i)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::execPrepared(%u)", i)
|
|
|
|
|
|
+ U_RETURN_POINTER(res, PGresult);
|
|
|
|
+ }
|
|
|
|
|
|
- U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
|
|
|
|
|
|
+ static void sendQueryPrepared()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::sendQueryPrepared()")
|
|
|
|
|
|
- *(unsigned int*)num2str = htonl(rnumber[i]);
|
|
|
|
|
|
+ U_INTERNAL_ASSERT_MAJOR(rnumber[0], 0)
|
|
|
|
|
|
- PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
|
|
|
|
|
|
+ *(unsigned int*)num2str = htonl(rnumber[0]);
|
|
|
|
|
|
- U_RETURN_POINTER(res, PGresult);
|
|
|
|
- }
|
|
|
|
|
|
+ (void) U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
|
|
|
|
+ }
|
|
|
|
|
|
- static void sendQueryPrepared(uint32_t i)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::sendQueryPrepared(%u)", i)
|
|
|
|
|
|
+ static void sendQueryPrepared(uint32_t i)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::sendQueryPrepared(%u)", i)
|
|
|
|
|
|
- U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
|
|
|
|
|
|
+ U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
|
|
|
|
|
|
- *(unsigned int*)num2str = htonl(rnumber[i]);
|
|
|
|
|
|
+ *(unsigned int*)num2str = htonl(rnumber[i]);
|
|
|
|
|
|
- (void) U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
|
|
|
|
- }
|
|
|
|
|
|
+ (void) U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
|
|
|
|
+ }
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- static void initResult()
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::initResult()")
|
|
|
|
|
|
+ static void initOneResult()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::initOneResult()")
|
|
|
|
|
|
- u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
|
|
|
- u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
|
|
|
- u_put_unalignedp64(wbuffer+16, U_MULTICHAR_CONSTANT64('1','3','3','3','1','\r','\n','C'));
|
|
|
|
- u_put_unalignedp64(wbuffer+24, U_MULTICHAR_CONSTANT64('o','n','t','e','n','t','-','T'));
|
|
|
|
- u_put_unalignedp64(wbuffer+32, U_MULTICHAR_CONSTANT64('y','p','e',':',' ','a','p','p'));
|
|
|
|
- u_put_unalignedp64(wbuffer+40, U_MULTICHAR_CONSTANT64('l','i','c','a','t','i','o','n'));
|
|
|
|
- u_put_unalignedp64(wbuffer+48, U_MULTICHAR_CONSTANT64('/','j','s','o','n','\r','\n','\r'));
|
|
|
|
- u_put_unalignedp16(wbuffer+56, U_MULTICHAR_CONSTANT16('\n','['));
|
|
|
|
|
|
+ U_INTERNAL_DUMP("wbuffer = %#.10S", wbuffer)
|
|
|
|
|
|
- pwbuffer = wbuffer + U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n[");
|
|
|
|
- }
|
|
|
|
|
|
+ if (u_get_unalignedp64(wbuffer+52) != U_MULTICHAR_CONSTANT64('\r','\n','{','"','i','d','"',':'))
|
|
|
|
+ {
|
|
|
|
+ u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
|
|
|
+ u_put_unalignedp32(wbuffer+16, U_MULTICHAR_CONSTANT32('3','1','\r','\n'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','a','p'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+36, U_MULTICHAR_CONSTANT64('p','l','i','c','a','t','i','o'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+52, U_MULTICHAR_CONSTANT64('\r','\n','{','"','i','d','"',':'));
|
|
|
|
|
|
- static void endResult()
|
|
|
|
- {
|
|
|
|
- U_TRACE_NO_PARAM(5, "World::endResult()")
|
|
|
|
|
|
+ pwbuffer = u_num2str32(rnumber[0], wbuffer + U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n{\"id\":"));
|
|
|
|
|
|
- *(pwbuffer-1) = ']';
|
|
|
|
|
|
+ u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
|
|
|
|
+ u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
|
|
|
|
+ }
|
|
|
|
|
|
- uint32_t len = pwbuffer-wbuffer,
|
|
|
|
- body_len = len - U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n");
|
|
|
|
|
|
+ U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(wbuffer), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
|
|
|
|
+ }
|
|
|
|
|
|
- pwbuffer = u_num2str32(body_len, wbuffer + U_CONSTANT_SIZE("Content-Length: "));
|
|
|
|
|
|
+ static void endOneResult()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::endOneResult()")
|
|
|
|
|
|
- while (*pwbuffer != '\r') *pwbuffer++ = ' ';
|
|
|
|
|
|
+ *ptr = '}';
|
|
|
|
|
|
- UClientImage_Base::wbuffer->setConstant(wbuffer, len);
|
|
|
|
- }
|
|
|
|
|
|
+ uint32_t len = ptr-wbuffer+1,
|
|
|
|
+ body_len = len - U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n");
|
|
|
|
|
|
- static void initOneResult()
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::initOneResult()")
|
|
|
|
|
|
+ U_NUM2STR16(wbuffer+U_CONSTANT_SIZE("Content-Length: "), body_len);
|
|
|
|
|
|
- u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
|
|
|
- u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
|
|
|
- u_put_unalignedp32(wbuffer+16, U_MULTICHAR_CONSTANT32('3','1','\r','\n'));
|
|
|
|
- u_put_unalignedp64(wbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
|
|
|
- u_put_unalignedp64(wbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','a','p'));
|
|
|
|
- u_put_unalignedp64(wbuffer+36, U_MULTICHAR_CONSTANT64('p','l','i','c','a','t','i','o'));
|
|
|
|
- u_put_unalignedp64(wbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
|
|
|
|
- u_put_unalignedp32(wbuffer+52, U_MULTICHAR_CONSTANT32('\r','\n','{','\0'));
|
|
|
|
|
|
+ UClientImage_Base::wbuffer->setConstant(wbuffer, len);
|
|
|
|
+ }
|
|
|
|
|
|
- pwbuffer = wbuffer + U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n{");
|
|
|
|
- }
|
|
|
|
|
|
+ static void handlerOneResult(uint32_t random)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::handlerOneResult(%u)", random)
|
|
|
|
|
|
- static void endOneResult()
|
|
|
|
- {
|
|
|
|
- U_TRACE_NO_PARAM(5, "World::endOneResult()")
|
|
|
|
|
|
+ initOneResult();
|
|
|
|
|
|
- *pwbuffer = '}';
|
|
|
|
|
|
+ ptr = u_num2str32(random, pwbuffer+16);
|
|
|
|
|
|
- uint32_t len = pwbuffer-wbuffer+1,
|
|
|
|
- body_len = len - U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n");
|
|
|
|
|
|
+ endOneResult();
|
|
|
|
+ }
|
|
|
|
|
|
- (void) u_num2str32(body_len, wbuffer+U_CONSTANT_SIZE("Content-Length: "));
|
|
|
|
|
|
+ static void initResult()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::initResult()")
|
|
|
|
|
|
- UClientImage_Base::wbuffer->setConstant(wbuffer, len);
|
|
|
|
- }
|
|
|
|
|
|
+ U_INTERNAL_DUMP("wbuffer = %#.10S", wbuffer)
|
|
|
|
|
|
- static void handlerOneResult(uint32_t uid, uint32_t random)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::handlerOneResult(%u,%u)", uid, random)
|
|
|
|
|
|
+ if (u_get_unalignedp64(wbuffer+56) != U_MULTICHAR_CONSTANT64('\n','[','{','"','i','d','"',':'))
|
|
|
|
+ {
|
|
|
|
+ u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
|
|
|
+ u_put_unalignedp64(wbuffer+16, U_MULTICHAR_CONSTANT64('1','3','3','3','1','\r','\n','C'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+24, U_MULTICHAR_CONSTANT64('o','n','t','e','n','t','-','T'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+32, U_MULTICHAR_CONSTANT64('y','p','e',':',' ','a','p','p'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+40, U_MULTICHAR_CONSTANT64('l','i','c','a','t','i','o','n'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+48, U_MULTICHAR_CONSTANT64('/','j','s','o','n','\r','\n','\r'));
|
|
|
|
+ u_put_unalignedp64(wbuffer+56, U_MULTICHAR_CONSTANT64('\n','[','{','"','i','d','"',':'));
|
|
|
|
|
|
- u_put_unalignedp32(pwbuffer, U_MULTICHAR_CONSTANT32('"','i','d','"'));
|
|
|
|
|
|
+ pwbuffer = u_num2str32(rnumber[0], wbuffer + U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n[{\"id\":"));
|
|
|
|
|
|
- pwbuffer[4] = ':';
|
|
|
|
|
|
+ u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
|
|
|
|
+ u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
|
|
|
|
+ }
|
|
|
|
|
|
- pwbuffer = u_num2str32(uid, pwbuffer+5);
|
|
|
|
|
|
+ U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(wbuffer), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
|
|
|
|
|
|
- u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
|
|
|
|
- u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
|
|
|
|
|
|
+ ptr = pwbuffer;
|
|
|
|
+ }
|
|
|
|
|
|
- pwbuffer = u_num2str32(random, pwbuffer+16);
|
|
|
|
- }
|
|
|
|
|
|
+ static void endResult()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::endResult()")
|
|
|
|
|
|
- static void handlerResult(uint32_t uid, uint32_t random)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::handlerResult(%u,%u)", uid, random)
|
|
|
|
|
|
+ *(ptr-1) = ']';
|
|
|
|
|
|
- u_put_unalignedp32(pwbuffer, U_MULTICHAR_CONSTANT32('{','"','i','d'));
|
|
|
|
- u_put_unalignedp16(pwbuffer+4, U_MULTICHAR_CONSTANT16('"',':'));
|
|
|
|
|
|
+ uint32_t len = ptr-wbuffer,
|
|
|
|
+ body_len = len - U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n");
|
|
|
|
|
|
- pwbuffer = u_num2str32(uid, pwbuffer+6);
|
|
|
|
|
|
+ ptr = u_num2str32(body_len, wbuffer + U_CONSTANT_SIZE("Content-Length: "));
|
|
|
|
|
|
- u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
|
|
|
|
- u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
|
|
|
|
|
|
+ while (*ptr != '\r') *ptr++ = ' ';
|
|
|
|
|
|
- pwbuffer = u_num2str32(random, pwbuffer+16);
|
|
|
|
|
|
+ UClientImage_Base::wbuffer->setConstant(wbuffer, len);
|
|
|
|
+ }
|
|
|
|
|
|
- u_put_unalignedp16(pwbuffer, U_MULTICHAR_CONSTANT16('}',','));
|
|
|
|
- pwbuffer += 2;
|
|
|
|
- }
|
|
|
|
|
|
+ static void addResult(uint32_t i)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::addResult(%u)", i)
|
|
|
|
|
|
- static void handlerResult(uint32_t i)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::handlerResult(%u)", i)
|
|
|
|
|
|
+ U_INTERNAL_ASSERT_MAJOR(i, 0)
|
|
|
|
|
|
- U_INTERNAL_ASSERT_POINTER(pworld_query)
|
|
|
|
|
|
+ u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('{','"','i','d'));
|
|
|
|
+ u_put_unalignedp16(ptr+4, U_MULTICHAR_CONSTANT16('"',':'));
|
|
|
|
|
|
- U_INTERNAL_DUMP("pworld_query->randomNumber = %u", pworld_query->randomNumber)
|
|
|
|
- }
|
|
|
|
|
|
+ ptr = u_num2str32(rnumber[i], ptr+6);
|
|
|
|
|
|
- static void handlerResultSql(uint32_t i)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::handlerResultSql(%u)", i)
|
|
|
|
|
|
+ u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
|
|
|
|
+ u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
|
|
|
|
+ }
|
|
|
|
|
|
- U_INTERNAL_ASSERT_POINTER(pworld_query)
|
|
|
|
|
|
+ static void addRandom(uint32_t random)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::addRandom(%u)", random)
|
|
|
|
|
|
- handlerResult(rnumber[i], pworld_query->randomNumber);
|
|
|
|
- }
|
|
|
|
|
|
+ ptr = u_num2str32(random, ptr+16);
|
|
|
|
|
|
- static void doUpdateNoSql(vPFu handlerUpdateNoSql)
|
|
|
|
- {
|
|
|
|
- U_TRACE(5, "World::doUpdateNoSql(%p)", handlerUpdateNoSql)
|
|
|
|
|
|
+ u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16('}',','));
|
|
|
|
+ ptr += 2;
|
|
|
|
+ }
|
|
|
|
|
|
- initResult();
|
|
|
|
|
|
+ static void handlerResult(uint32_t i, uint32_t random)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::handlerResult(%u,%u)", i, random)
|
|
|
|
|
|
- for (uint32_t i = 0, n = UHTTP::getFormFirstNumericValue(1, 500); i < n; ++i)
|
|
|
|
- {
|
|
|
|
- handlerUpdateNoSql(i);
|
|
|
|
|
|
+ if (i) addResult(i);
|
|
|
|
|
|
- handlerResult(rnumber[i], rnum);
|
|
|
|
- }
|
|
|
|
|
|
+ addRandom(random);
|
|
|
|
+ }
|
|
|
|
|
|
- endResult();
|
|
|
|
- }
|
|
|
|
|
|
+ static void doUpdateNoSql(vPFu handlerUpdateNoSql)
|
|
|
|
+ {
|
|
|
|
+ U_TRACE(5, "World::doUpdateNoSql(%p)", handlerUpdateNoSql)
|
|
|
|
|
|
- static void handlerFork()
|
|
|
|
- {
|
|
|
|
- U_TRACE_NO_PARAM(5, "World::handlerFork()")
|
|
|
|
|
|
+ initResult();
|
|
|
|
|
|
- if (rnumber[0] == 0) for (uint32_t i = 0; i < 500; ++i) rnumber[i] = u_get_num_random_range1(10000);
|
|
|
|
- }
|
|
|
|
|
|
+ for (uint32_t i = 0, n = UHTTP::getFormFirstNumericValue(1, 500); i < n; ++i)
|
|
|
|
+ {
|
|
|
|
+ handlerUpdateNoSql(i);
|
|
|
|
|
|
- static void handlerForkSql()
|
|
|
|
- {
|
|
|
|
- U_TRACE_NO_PARAM(5, "World::handlerForkSql()")
|
|
|
|
|
|
+ handlerResult(i, rnum);
|
|
|
|
+ }
|
|
|
|
|
|
- if (psql_query == U_NULLPTR)
|
|
|
|
- {
|
|
|
|
- U_NEW(UOrmSession, psql_query, UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));
|
|
|
|
|
|
+ endResult();
|
|
|
|
+ }
|
|
|
|
|
|
- if (psql_query->isReady() == false)
|
|
|
|
- {
|
|
|
|
- U_WARNING("World::handlerForkSql(): we cound't connect to db");
|
|
|
|
|
|
+ static void handlerInitSql()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::handlerInitSql()")
|
|
|
|
|
|
- U_DELETE(psql_query)
|
|
|
|
|
|
+# ifdef U_STATIC_ORM_DRIVER_PGSQL
|
|
|
|
+ U_INTERNAL_DUMP("UServer_Base::handler_db1 = %p", UServer_Base::handler_db1)
|
|
|
|
|
|
- psql_query = U_NULLPTR;
|
|
|
|
|
|
+ if (UServer_Base::handler_db1 == U_NULLPTR)
|
|
|
|
+ {
|
|
|
|
+ U_NEW(UEventDB, UServer_Base::handler_db1, UEventDB);
|
|
|
|
+ }
|
|
|
|
+# endif
|
|
|
|
+ }
|
|
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ static void handlerFork()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::handlerFork()")
|
|
|
|
|
|
- U_NEW(UOrmStatement, pstmt_query, UOrmStatement(*psql_query, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
|
|
|
|
|
|
+ if (rnumber[0] == 0) for (uint32_t i = 0; i <= 500; ++i) rnumber[i] = u_get_num_random_range1(10000);
|
|
|
|
+ }
|
|
|
|
|
|
- U_NEW(World, pworld_query, World);
|
|
|
|
|
|
+ static void handlerForkSql()
|
|
|
|
+ {
|
|
|
|
+ U_TRACE_NO_PARAM(5, "World::handlerForkSql()")
|
|
|
|
|
|
- pstmt_query->use( pworld_query->id);
|
|
|
|
- pstmt_query->into(pworld_query->randomNumber);
|
|
|
|
|
|
+ if (psql_query == U_NULLPTR)
|
|
|
|
+ {
|
|
|
|
+ U_NEW(UOrmSession, psql_query, UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));
|
|
|
|
|
|
-# ifdef U_STATIC_ORM_DRIVER_PGSQL
|
|
|
|
- if (UOrmDriver::isPGSQL())
|
|
|
|
- {
|
|
|
|
- conn = (PGconn*)(pdrv = (UOrmDriverPgSql*)psql_query->getDriver())->UOrmDriver::connection;
|
|
|
|
- pstmt = (UPgSqlStatement*)pstmt_query->getStatement();
|
|
|
|
|
|
+ if (psql_query->isReady() == false)
|
|
|
|
+ {
|
|
|
|
+ U_WARNING("World::handlerForkSql(): we cound't connect to db");
|
|
|
|
|
|
- (void) pstmt->setBindParam(pdrv);
|
|
|
|
|
|
+ U_DELETE(psql_query)
|
|
|
|
|
|
- pstmt->paramValues[0] = num2str;
|
|
|
|
- pstmt->paramLengths[0] = sizeof(unsigned int);
|
|
|
|
- }
|
|
|
|
-# endif
|
|
|
|
|
|
+ psql_query = U_NULLPTR;
|
|
|
|
|
|
- handlerFork();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- const char* dump(bool breset) const;
|
|
|
|
-#endif
|
|
|
|
|
|
+ U_NEW(UOrmStatement, pstmt_query, UOrmStatement(*psql_query, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
|
|
|
|
+
|
|
|
|
+ U_NEW(World, pworld_query, World);
|
|
|
|
+
|
|
|
|
+ pstmt_query->use( pworld_query->id);
|
|
|
|
+ pstmt_query->into(pworld_query->randomNumber);
|
|
|
|
+
|
|
|
|
+# ifdef U_STATIC_ORM_DRIVER_PGSQL
|
|
|
|
+ if (UOrmDriver::isPGSQL())
|
|
|
|
+ {
|
|
|
|
+ UOrmDriverPgSql* pdrv = (UOrmDriverPgSql*)psql_query->getDriver();
|
|
|
|
+
|
|
|
|
+ conn = (PGconn*)pdrv->UOrmDriver::connection;
|
|
|
|
+ pstmt = (UPgSqlStatement*)pstmt_query->getStatement();
|
|
|
|
+
|
|
|
|
+ (void) pstmt->setBindParam(pdrv);
|
|
|
|
+
|
|
|
|
+ pstmt->paramValues[0] = num2str;
|
|
|
|
+ pstmt->paramLengths[0] = sizeof(unsigned int);
|
|
|
|
+
|
|
|
|
+ UServer_Base::handler_db1->setConnection(conn);
|
|
|
|
+ }
|
|
|
|
+# endif
|
|
|
|
+
|
|
|
|
+ handlerFork();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
private:
|
|
private:
|
|
- U_DISALLOW_ASSIGN(World)
|
|
|
|
|
|
+ U_DISALLOW_ASSIGN(World)
|
|
};
|
|
};
|
|
#endif
|
|
#endif
|