cwUi.h/cpp : Add queueBlkCnt and queueBlkByteCnt to websock based API's.

Removed websockTimeOutMs from UI cfg. and replace it as an argument to ui::ws::exec().
This commit is contained in:
kevin 2024-03-28 19:47:29 -04:00
parent 60e6c2f772
commit 98ed33d2cc
2 changed files with 100 additions and 81 deletions

View File

@ -166,7 +166,7 @@ namespace cw
bucket_t* b = p->hashA + hash_idx; bucket_t* b = p->hashA + hash_idx;
for(; b!=nullptr; b=b->link) for(; b!=nullptr; b=b->link)
if( b->ele->appId==appId && b->ele->logical_parent->uuId==parentUuId && (chanId==kInvalidId || b->ele->chanId==chanId) ) if( b->ele != nullptr && b->ele->logical_parent!=nullptr && b->ele->appId==appId && b->ele->logical_parent->uuId==parentUuId && (chanId==kInvalidId || b->ele->chanId==chanId) )
return b->ele->uuId; return b->ele->uuId;
} }
@ -2249,7 +2249,6 @@ namespace cw
void* cbArg; void* cbArg;
uiCallback_t uiCbFunc; uiCallback_t uiCbFunc;
websock::cbFunc_t wsCbFunc; websock::cbFunc_t wsCbFunc;
unsigned wsTimeOutMs;
unsigned idleMsgPeriodMs; unsigned idleMsgPeriodMs;
time::spec_t lastRecvMsgTimeStamp; time::spec_t lastRecvMsgTimeStamp;
} ui_ws_t; } ui_ws_t;
@ -2331,13 +2330,18 @@ cw::rc_t cw::ui::ws::parseArgs( const object_t& o, args_t& args, const char* ob
"rcvBufByteN", args.rcvBufByteN, "rcvBufByteN", args.rcvBufByteN,
"xmtBufByteN", args.xmtBufByteN, "xmtBufByteN", args.xmtBufByteN,
"fmtBufByteN", args.fmtBufByteN, "fmtBufByteN", args.fmtBufByteN,
"websockTimeOutMs", args.wsTimeOutMs,
"idleMsgPeriodMs", args.idleMsgPeriodMs, "idleMsgPeriodMs", args.idleMsgPeriodMs,
"queueBlkCnt", args.queueBlkCnt,
"queueBlkByteCnt", args.queueBlkByteCnt,
"uiCfgFn", uiCfgFn )) != kOkRC ) "uiCfgFn", uiCfgFn )) != kOkRC )
{ {
rc = cwLogError(rc,"'ui' cfg. parse failed."); rc = cwLogError(rc,"'ui' cfg. parse failed.");
} }
if( op->find_child("websockTimeOutMs") != nullptr )
cwLogWarning("The UI parameter 'websockTimeOutMs' is obsolete and ignored.");
// expand the physical root directory // expand the physical root directory
if((physRootDir = filesys::expandPath( args.physRootDir)) == nullptr ) if((physRootDir = filesys::expandPath( args.physRootDir)) == nullptr )
{ {
@ -2388,11 +2392,12 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
appIdMapN, appIdMapN,
wsCbFunc, wsCbFunc,
args.dfltPageFn, args.dfltPageFn,
args.wsTimeOutMs,
args.idleMsgPeriodMs, args.idleMsgPeriodMs,
args.rcvBufByteN, args.rcvBufByteN,
args.xmtBufByteN, args.xmtBufByteN,
args.fmtBufByteN ); args.fmtBufByteN,
args.queueBlkCnt,
args.queueBlkByteCnt);
} }
@ -2406,11 +2411,12 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
unsigned appIdMapN, unsigned appIdMapN,
websock::cbFunc_t wsCbFunc, websock::cbFunc_t wsCbFunc,
const char* dfltPageFn, const char* dfltPageFn,
unsigned websockTimeOutMs,
unsigned idleMsgPeriodMs, unsigned idleMsgPeriodMs,
unsigned rcvBufByteN, unsigned rcvBufByteN,
unsigned xmtBufByteN, unsigned xmtBufByteN,
unsigned fmtBufByteN ) unsigned fmtBufByteN,
unsigned queueBlkCnt,
unsigned queueBlkByteCnt )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
@ -2430,7 +2436,7 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
void* wsCbA = wsCbFunc==nullptr ? p : cbArg; void* wsCbA = wsCbFunc==nullptr ? p : cbArg;
// create the websocket // create the websocket
if((rc = websock::create(p->wsH, wsCbF, wsCbA, physRootDir, dfltPageFn, port, protocolA, protocolN )) != kOkRC ) if((rc = websock::create(p->wsH, wsCbF, wsCbA, physRootDir, dfltPageFn, port, protocolA, protocolN, queueBlkCnt, queueBlkByteCnt )) != kOkRC )
{ {
cwLogError(rc,"UI Websock create failed."); cwLogError(rc,"UI Websock create failed.");
goto errLabel; goto errLabel;
@ -2446,7 +2452,6 @@ cw::rc_t cw::ui::ws::create( handle_t& h,
p->cbArg = cbArg; p->cbArg = cbArg;
p->uiCbFunc = uiCbFunc; p->uiCbFunc = uiCbFunc;
p->wsCbFunc = wsCbFunc; p->wsCbFunc = wsCbFunc;
p->wsTimeOutMs = websockTimeOutMs;
p->idleMsgPeriodMs = idleMsgPeriodMs; p->idleMsgPeriodMs = idleMsgPeriodMs;
// initialize the last received msg // initialize the last received msg
time::get(p->lastRecvMsgTimeStamp); time::get(p->lastRecvMsgTimeStamp);
@ -2479,13 +2484,13 @@ cw::rc_t cw::ui::ws::destroy( handle_t& h )
return rc; return rc;
} }
cw::rc_t cw::ui::ws::exec( handle_t h ) cw::rc_t cw::ui::ws::exec( handle_t h, unsigned wsTimeOutMs )
{ {
rc_t rc = kOkRC;
ui_ws_t* p = _handleToPtr(h); ui_ws_t* p = _handleToPtr(h);
rc_t rc = kOkRC;
time::spec_t t; time::spec_t t;
if((rc = websock::exec( p->wsH, p->wsTimeOutMs )) != kOkRC) if((rc = websock::exec( p->wsH, wsTimeOutMs )) != kOkRC)
cwLogError(rc,"The UI websock execution failed."); cwLogError(rc,"The UI websock execution failed.");
// make the idle callback // make the idle callback
@ -2500,6 +2505,7 @@ cw::rc_t cw::ui::ws::exec( handle_t h )
return rc; return rc;
} }
cw::rc_t cw::ui::ws::onReceive( handle_t h, unsigned protocolId, unsigned sessionId, websock::msgTypeId_t msg_type, const void* msg, unsigned byteN ) cw::rc_t cw::ui::ws::onReceive( handle_t h, unsigned protocolId, unsigned sessionId, websock::msgTypeId_t msg_type, const void* msg, unsigned byteN )
{ {
ui_ws_t* p = _handleToPtr(h); ui_ws_t* p = _handleToPtr(h);
@ -2521,6 +2527,7 @@ cw::ui::handle_t cw::ui::ws::uiHandle( handle_t h )
return p->uiH; return p->uiH;
} }
void cw::ui::ws::realTimeReport( handle_t h ) void cw::ui::ws::realTimeReport( handle_t h )
{ {
ui_ws_t* p = _handleToPtr(h); ui_ws_t* p = _handleToPtr(h);
@ -2539,6 +2546,7 @@ namespace cw
{ {
ws::handle_t wsUiH; ws::handle_t wsUiH;
thread::handle_t thH; thread::handle_t thH;
unsigned wsTimeOutMs;
} ui_ws_srv_t; } ui_ws_srv_t;
ui_ws_srv_t* _handleToPtr(handle_t h ) ui_ws_srv_t* _handleToPtr(handle_t h )
@ -2563,7 +2571,7 @@ namespace cw
ui_ws_srv_t* p = static_cast<ui_ws_srv_t*>(arg); ui_ws_srv_t* p = static_cast<ui_ws_srv_t*>(arg);
rc_t rc; rc_t rc;
if((rc = ws::exec(p->wsUiH)) != kOkRC ) if((rc = ws::exec(p->wsUiH,p->wsTimeOutMs)) != kOkRC )
{ {
cwLogError(rc,"Websocket UI exec failed."); cwLogError(rc,"Websocket UI exec failed.");
} }
@ -2574,6 +2582,34 @@ namespace cw
} }
} }
cw::rc_t cw::ui::srv::create( handle_t& h,
const ws::args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
const appIdMap_t* appIdMapA,
unsigned appIdMapN,
unsigned wsTimeOutMs,
websock::cbFunc_t wsCbFunc )
{
return create(h,
args.port,
args.physRootDir,
cbArg,
uiCbFunc,
args.uiRsrc,
appIdMapA,
appIdMapN,
wsTimeOutMs,
wsCbFunc,
args.dfltPageFn,
args.idleMsgPeriodMs,
args.rcvBufByteN,
args.xmtBufByteN,
args.fmtBufByteN,
args.queueBlkCnt,
args.queueBlkByteCnt );
}
cw::rc_t cw::ui::srv::create( handle_t& h, cw::rc_t cw::ui::srv::create( handle_t& h,
unsigned port, unsigned port,
const char* physRootDir, const char* physRootDir,
@ -2582,12 +2618,15 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
const object_t* uiRsrc, const object_t* uiRsrc,
const appIdMap_t* appIdMapA, const appIdMap_t* appIdMapA,
unsigned appIdMapN, unsigned appIdMapN,
unsigned wsTimeOutMs,
websock::cbFunc_t wsCbFunc, websock::cbFunc_t wsCbFunc,
const char* dfltPageFn, const char* dfltPageFn,
unsigned websockTimeOutMs, unsigned idleMsgPeriodMs,
unsigned rcvBufByteN, unsigned rcvBufByteN,
unsigned xmtBufByteN, unsigned xmtBufByteN,
unsigned fmtBufByteN ) unsigned fmtBufByteN,
unsigned queueBlkCnt,
unsigned queueBlkByteCnt )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
if((rc = destroy(h)) != kOkRC ) if((rc = destroy(h)) != kOkRC )
@ -2595,7 +2634,7 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
ui_ws_srv_t* p = mem::allocZ<ui_ws_srv_t>(); ui_ws_srv_t* p = mem::allocZ<ui_ws_srv_t>();
if((rc = ws::create(p->wsUiH, port, physRootDir, cbArg, uiCbFunc, uiRsrc,appIdMapA, appIdMapN, wsCbFunc, dfltPageFn, websockTimeOutMs, rcvBufByteN, xmtBufByteN, fmtBufByteN )) != kOkRC ) if((rc = ws::create(p->wsUiH, port, physRootDir, cbArg, uiCbFunc, uiRsrc,appIdMapA, appIdMapN, wsCbFunc, dfltPageFn, idleMsgPeriodMs, rcvBufByteN, xmtBufByteN, fmtBufByteN, queueBlkCnt, queueBlkByteCnt )) != kOkRC )
{ {
cwLogError(rc,"The websock UI creationg failed."); cwLogError(rc,"The websock UI creationg failed.");
goto errLabel; goto errLabel;
@ -2607,6 +2646,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
goto errLabel; goto errLabel;
} }
p->wsTimeOutMs = wsTimeOutMs;
h.set(p); h.set(p);
errLabel: errLabel:
@ -2616,32 +2657,6 @@ cw::rc_t cw::ui::srv::create( handle_t& h,
return rc; return rc;
} }
cw::rc_t cw::ui::srv::create( handle_t& h,
const ws::args_t& args,
void* cbArg,
uiCallback_t uiCbFunc,
const appIdMap_t* appIdMapA,
unsigned appIdMapN,
websock::cbFunc_t wsCbFunc )
{
return create(h,
args.port,
args.physRootDir,
cbArg,
uiCbFunc,
args.uiRsrc,
appIdMapA,
appIdMapN,
wsCbFunc,
args.dfltPageFn,
args.wsTimeOutMs,
args.rcvBufByteN,
args.xmtBufByteN,
args.fmtBufByteN );
}
cw::rc_t cw::ui::srv::destroy( handle_t& h ) cw::rc_t cw::ui::srv::destroy( handle_t& h )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;

22
cwUi.h
View File

@ -188,8 +188,9 @@ namespace cw
unsigned rcvBufByteN; unsigned rcvBufByteN;
unsigned xmtBufByteN; unsigned xmtBufByteN;
unsigned fmtBufByteN; unsigned fmtBufByteN;
unsigned wsTimeOutMs;
unsigned idleMsgPeriodMs; // min period without messages before an idle message is generated unsigned idleMsgPeriodMs; // min period without messages before an idle message is generated
unsigned queueBlkCnt;
unsigned queueBlkByteCnt;
} args_t; } args_t;
rc_t parseArgs( const object_t& o, args_t& args, const char* object_label="ui" ); rc_t parseArgs( const object_t& o, args_t& args, const char* object_label="ui" );
@ -214,20 +215,20 @@ namespace cw
unsigned appIdMapN = 0, unsigned appIdMapN = 0,
websock::cbFunc_t wsCbFunc = nullptr, websock::cbFunc_t wsCbFunc = nullptr,
const char* dfltPageFn = "index.html", const char* dfltPageFn = "index.html",
unsigned websockTimeOutMs = 50,
unsigned idleMsgPeriodMs = 50, unsigned idleMsgPeriodMs = 50,
unsigned rcvBufByteN = 1024, unsigned rcvBufByteN = 1024,
unsigned xmtBufByteN = 1024, unsigned xmtBufByteN = 1024,
unsigned fmtBufByteN = 4096 unsigned fmtBufByteN = 4096,
); unsigned queueBlkCnt = 4,
unsigned queueBlkByteCnt = 4096 );
rc_t destroy( handle_t& h ); rc_t destroy( handle_t& h );
// This function should be called periodically to send and receive // This function should be called periodically to send and receive
// queued messages to and from the websocket. // queued messages to and from the websocket.
// Note that this call may block for up to 'wsTimeOutMs' milliseconds // Note that this call may block for up to 'wsTimeOutMs' milliseconds
// on the websocket handle. // while waiting for incoming websocket messages.
rc_t exec( handle_t h ); rc_t exec( handle_t h, unsigned wsTimeOutMs );
// This function executes the internal default websock callback function. // This function executes the internal default websock callback function.
// It is useful if the user provides a custom websock callback function // It is useful if the user provides a custom websock callback function
@ -236,7 +237,6 @@ namespace cw
websock::handle_t websockHandle( handle_t h ); websock::handle_t websockHandle( handle_t h );
ui::handle_t uiHandle( handle_t h ); ui::handle_t uiHandle( handle_t h );
void realTimeReport( handle_t h ); void realTimeReport( handle_t h );
} }
@ -252,6 +252,7 @@ namespace cw
uiCallback_t uiCbFunc, uiCallback_t uiCbFunc,
const appIdMap_t* appIdMapA = nullptr, const appIdMap_t* appIdMapA = nullptr,
unsigned appIdMapN = 0, unsigned appIdMapN = 0,
unsigned wsTimeOutMs = 50,
websock::cbFunc_t wsCbFunc = nullptr ); websock::cbFunc_t wsCbFunc = nullptr );
rc_t create( handle_t& h, rc_t create( handle_t& h,
@ -262,12 +263,15 @@ namespace cw
const object_t* uiRsrc = nullptr, const object_t* uiRsrc = nullptr,
const appIdMap_t* appIdMapA = nullptr, const appIdMap_t* appIdMapA = nullptr,
unsigned appIdMapN = 0, unsigned appIdMapN = 0,
unsigned wsTimeOutMs = 50,
websock::cbFunc_t wsCbFunc = nullptr, websock::cbFunc_t wsCbFunc = nullptr,
const char* dfltPageFn = "index.html", const char* dfltPageFn = "index.html",
unsigned websockTimeOutMs = 50, unsigned idleMsgPeriodMs = 50,
unsigned rcvBufByteN = 1024, unsigned rcvBufByteN = 1024,
unsigned xmtBufByteN = 1024, unsigned xmtBufByteN = 1024,
unsigned fmtBufByteN = 4096 ); unsigned fmtBufByteN = 4096,
unsigned queueBlkCnt = 4,
unsigned queueBlkByteCnt = 4096 );
rc_t destroy( handle_t& h ); rc_t destroy( handle_t& h );