mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 14:10:54 -04:00
Solve race condition in JSON API restart
Improve atomic access to restbed service Protect JSON API restart against bursts Fix JSON API error condition enum registration Provide ostream helper for error_condition Provide optional forced thread cancel for debugging purpose, disabled by default at compile time define RS_THREAD_FORCE_STOP to enable it Avoid double fullstop in retroshare-gui json api apply button
This commit is contained in:
parent
7757c685c5
commit
039e8f653d
8 changed files with 236 additions and 72 deletions
|
@ -112,28 +112,41 @@ QString JsonApiPage::helpText() const { return ""; }
|
|||
|
||||
bool JsonApiPage::checkStartJsonApi()
|
||||
{
|
||||
if(!Settings->getJsonApiEnabled())
|
||||
return false;
|
||||
if(!Settings->getJsonApiEnabled()) return false;
|
||||
|
||||
rsJsonApi->setListeningPort(Settings->getJsonApiPort());
|
||||
rsJsonApi->setBindingAddress(Settings->getJsonApiListenAddress().toStdString());
|
||||
rsJsonApi->restart();
|
||||
|
||||
const auto rErr = rsJsonApi->restart();
|
||||
if(rErr == RsJsonApiErrorNum::NOT_A_MACHINE_GUN)
|
||||
{
|
||||
RsDbg() << __PRETTY_FUNCTION__ << " apparently the user is attempting "
|
||||
<< "to restart JSON API service in a burst. Re-scheduling "
|
||||
<< "restart in a while..." << std::endl;
|
||||
RsThread::async([]()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
rsJsonApi->restart();
|
||||
});
|
||||
}
|
||||
else if(rErr)
|
||||
{
|
||||
RsErr() << __PRETTY_FUNCTION__ << rErr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ void JsonApiPage::checkShutdownJsonApi()
|
||||
{
|
||||
if(!rsJsonApi->isRunning()) return;
|
||||
rsJsonApi->fullstop(); // this is a blocks until the thread is terminated.
|
||||
}
|
||||
|
||||
void JsonApiPage::onApplyClicked()
|
||||
{
|
||||
// restart
|
||||
|
||||
checkShutdownJsonApi();
|
||||
checkStartJsonApi();
|
||||
// restart
|
||||
checkStartJsonApi();
|
||||
}
|
||||
|
||||
void JsonApiPage::checkToken(QString s)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue