From c2e891d288fff52d7e4f604303c5c2ead9281471 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sat, 31 Aug 2019 22:25:08 +0000 Subject: [PATCH] Update the C getnodedat/putnodedat API to not require that the node file (ctrl/node.dab) is constantly closed and re-opened for every non-locking read. This is really slow across network file systems and unnecessary, so use a similar optimization as the C++ sbbs_t class where the file can (and normally is) left open across multiple consecutive reads. --- src/sbbs3/ctrl/MainFormUnit.cpp | 4 ++-- src/sbbs3/ctrl/NodeFormUnit.cpp | 40 +++++++++++++++------------------ src/sbbs3/ctrl/NodeFormUnit.h | 6 ++--- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/sbbs3/ctrl/MainFormUnit.cpp b/src/sbbs3/ctrl/MainFormUnit.cpp index ef89a5338f..be01e35f0c 100644 --- a/src/sbbs3/ctrl/MainFormUnit.cpp +++ b/src/sbbs3/ctrl/MainFormUnit.cpp @@ -3865,10 +3865,10 @@ void __fastcall TMainForm::ClearErrorsExecute(TObject *Sender) node_t node; for(int i=0;i<cfg.sys_nodes;i++) { int file; - if(NodeForm->getnodedat(i+1,&node,&file)) + if(NodeForm->getnodedat(i+1,&node, /*lockit: */true)) break; node.errors=0; - if(NodeForm->putnodedat(i+1,&node,file)) + if(NodeForm->putnodedat(i+1,&node)) break; } } diff --git a/src/sbbs3/ctrl/NodeFormUnit.cpp b/src/sbbs3/ctrl/NodeFormUnit.cpp index 5b67032e6b..a873f17a87 100644 --- a/src/sbbs3/ctrl/NodeFormUnit.cpp +++ b/src/sbbs3/ctrl/NodeFormUnit.cpp @@ -59,6 +59,7 @@ __fastcall TNodeForm::TNodeForm(TComponent* Owner) { MainForm->bbs_startup.node_spybuf =(RingBuf**)calloc(1,sizeof(RingBuf*)*MAX_NODES); + file = -1; } //--------------------------------------------------------------------------- void __fastcall TNodeForm::FormHide(TObject *Sender) @@ -66,12 +67,12 @@ void __fastcall TNodeForm::FormHide(TObject *Sender) MainForm->ViewNodes->Checked=false; } //--------------------------------------------------------------------------- -int __fastcall TNodeForm::getnodedat(int node_num, node_t* node, int* file) +int __fastcall TNodeForm::getnodedat(int node_num, node_t* node, bool lockit) { char errmsg[128]; int err; - if((err=::getnodedat(&MainForm->cfg,node_num,node,file))!=0) { + if((err=::getnodedat(&MainForm->cfg,node_num,node,lockit,&file))!=0) { sprintf(errmsg,"getnodedat returned %d",err); Application->MessageBox(errmsg ,"ERROR",MB_OK|MB_ICONEXCLAMATION); @@ -80,12 +81,12 @@ int __fastcall TNodeForm::getnodedat(int node_num, node_t* node, int* file) return(err); } //--------------------------------------------------------------------------- -int __fastcall TNodeForm::putnodedat(int node_num, node_t* node, int file) +int __fastcall TNodeForm::putnodedat(int node_num, node_t* node) { char errmsg[128]; int err; - if((err=::putnodedat(&MainForm->cfg,node_num,node, file))!=0) { + if((err=::putnodedat(&MainForm->cfg,node_num,node, /* closeit: */false,file))!=0) { sprintf(errmsg,"putnodedat(%d) returned %d",file,err); Application->MessageBox(errmsg ,"ERROR",MB_OK|MB_ICONEXCLAMATION); @@ -196,15 +197,14 @@ void __fastcall TNodeForm::TimerTick(TObject *Sender) void __fastcall TNodeForm::InterruptNodeButtonClick(TObject *Sender) { int i; - int file; node_t node; for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,&file)) + if(getnodedat(i+1,&node, /* lockit: */true)) break; node.misc^=NODE_INTR; - if(putnodedat(i+1,&node,file)) + if(putnodedat(i+1,&node)) break; } TimerTick(Sender); @@ -214,15 +214,14 @@ void __fastcall TNodeForm::InterruptNodeButtonClick(TObject *Sender) void __fastcall TNodeForm::LockNodeButtonClick(TObject *Sender) { int i; - int file; node_t node; for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,&file)) + if(getnodedat(i+1,&node, /*lockit: */true)) break; node.misc^=NODE_LOCK; - if(putnodedat(i+1,&node,file)) + if(putnodedat(i+1,&node)) break; } TimerTick(Sender); @@ -232,15 +231,14 @@ void __fastcall TNodeForm::LockNodeButtonClick(TObject *Sender) void __fastcall TNodeForm::RerunNodeButtonClick(TObject *Sender) { int i; - int file; node_t node; for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,&file)) + if(getnodedat(i+1,&node, /*lockit: */true)) break; node.misc^=NODE_RRUN; - if(putnodedat(i+1,&node,file)) + if(putnodedat(i+1,&node)) break; } TimerTick(Sender); @@ -262,12 +260,11 @@ void __fastcall TNodeForm::SelectAllMenuItemClick(TObject *Sender) void __fastcall TNodeForm::DownButtonClick(TObject *Sender) { int i; - int file; node_t node; for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,&file)) + if(getnodedat(i+1,&node, /*lockit: */true)) break; if(node.status==NODE_WFC) node.status=NODE_OFFLINE; @@ -275,7 +272,7 @@ void __fastcall TNodeForm::DownButtonClick(TObject *Sender) node.status=NODE_WFC; else node.misc^=NODE_DOWN; - if(putnodedat(i+1,&node,file)) + if(putnodedat(i+1,&node)) break; } TimerTick(Sender); @@ -285,15 +282,14 @@ void __fastcall TNodeForm::DownButtonClick(TObject *Sender) void __fastcall TNodeForm::ClearErrorButtonClick(TObject *Sender) { int i; - int file; node_t node; for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,&file)) + if(getnodedat(i+1,&node, /*lockit: */true)) break; node.errors=0; - if(putnodedat(i+1,&node,file)) + if(putnodedat(i+1,&node)) break; } TimerTick(Sender); @@ -309,7 +305,7 @@ void __fastcall TNodeForm::ChatButtonClick(TObject *Sender) for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,NULL)) + if(getnodedat(i+1,&node, /*lockit: */false)) break; if(node.status==NODE_WFC || node.status>NODE_QUIET) continue; @@ -352,7 +348,7 @@ void __fastcall TNodeForm::UserEditButtonClick(TObject *Sender) for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,NULL)) + if(getnodedat(i+1,&node, /*lockit: */false)) break; if(node.useron==0) continue; @@ -378,7 +374,7 @@ void __fastcall TNodeForm::UserMsgButtonClick(TObject *Sender) UserMsgForm->Memo->Lines->Add(""); for(i=0;i<ListBox->Items->Count;i++) if(ListBox->Selected[i]==true) { - if(getnodedat(i+1,&node,NULL)) + if(getnodedat(i+1,&node, /*lockit: */false)) break; if(node.useron==0) continue; diff --git a/src/sbbs3/ctrl/NodeFormUnit.h b/src/sbbs3/ctrl/NodeFormUnit.h index 42afd95d69..a001d7480b 100644 --- a/src/sbbs3/ctrl/NodeFormUnit.h +++ b/src/sbbs3/ctrl/NodeFormUnit.h @@ -91,11 +91,11 @@ __published: // IDE-managed Components void __fastcall UserMsgButtonClick(TObject *Sender); void __fastcall RefreshMenuItemClick(TObject *Sender); private: // User declarations - + int file; public: // User declarations __fastcall TNodeForm(TComponent* Owner); - int __fastcall getnodedat(int node_num, node_t* node, int* file); - int __fastcall putnodedat(int node_num, node_t* node, int file); + int __fastcall getnodedat(int node_num, node_t* node, bool lockit); + int __fastcall putnodedat(int node_num, node_t* node); }; //--------------------------------------------------------------------------- -- GitLab