Proper shutdown procedure
This commit is contained in:
@@ -487,10 +487,19 @@ Connection::~Connection() {
|
|||||||
|
|
||||||
void Connection::doRPC(const json& payload, const std::function<void(json)>& cb,
|
void Connection::doRPC(const json& payload, const std::function<void(json)>& cb,
|
||||||
const std::function<void(QNetworkReply*, const json&)>& ne) {
|
const std::function<void(QNetworkReply*, const json&)>& ne) {
|
||||||
|
if (shutdownInProgress) {
|
||||||
|
qDebug() << "Ignoring RPC because shutdown in progress";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump()));
|
QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump()));
|
||||||
|
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
if (shutdownInProgress) {
|
||||||
|
qDebug() << "Ignoring callback because shutdown in progress";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
auto parsed = json::parse(reply->readAll(), nullptr, false);
|
auto parsed = json::parse(reply->readAll(), nullptr, false);
|
||||||
@@ -530,3 +539,10 @@ void Connection::showTxError(const QString& error) {
|
|||||||
QMessageBox::critical(main, "Transaction Error", "There was an error sending the transaction. The error was: \n\n"
|
QMessageBox::critical(main, "Transaction Error", "There was an error sending the transaction. The error was: \n\n"
|
||||||
+ error, QMessageBox::StandardButton::Ok);
|
+ error, QMessageBox::StandardButton::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent all future calls from going through
|
||||||
|
*/
|
||||||
|
void Connection::shutdown() {
|
||||||
|
shutdownInProgress = true;
|
||||||
|
}
|
||||||
@@ -90,6 +90,8 @@ public:
|
|||||||
std::shared_ptr<ConnectionConfig> config;
|
std::shared_ptr<ConnectionConfig> config;
|
||||||
MainWindow* main;
|
MainWindow* main;
|
||||||
|
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
void doRPC(const json& payload, const std::function<void(json)>& cb,
|
void doRPC(const json& payload, const std::function<void(json)>& cb,
|
||||||
const std::function<void(QNetworkReply*, const json&)>& ne);
|
const std::function<void(QNetworkReply*, const json&)>& ne);
|
||||||
void doRPCWithDefaultErrorHandling(const json& payload, const std::function<void(json)>& cb);
|
void doRPCWithDefaultErrorHandling(const json& payload, const std::function<void(json)>& cb);
|
||||||
@@ -143,6 +145,9 @@ public:
|
|||||||
});
|
});
|
||||||
waitTimer->start(100);
|
waitTimer->start(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool shutdownInProgress = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -857,6 +857,8 @@ void RPC::shutdownZcashd() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
conn->doRPCWithDefaultErrorHandling(payload, [=](auto) {});
|
conn->doRPCWithDefaultErrorHandling(payload, [=](auto) {});
|
||||||
|
conn->shutdown();
|
||||||
|
|
||||||
|
|
||||||
QMessageBox d(main);
|
QMessageBox d(main);
|
||||||
d.setIcon(QMessageBox::Icon::Information);
|
d.setIcon(QMessageBox::Icon::Information);
|
||||||
@@ -869,11 +871,12 @@ void RPC::shutdownZcashd() {
|
|||||||
// We capture by reference all the local variables because of the d.exec()
|
// We capture by reference all the local variables because of the d.exec()
|
||||||
// below, which blocks this function until we exit.
|
// below, which blocks this function until we exit.
|
||||||
QObject::connect(&waiter, &QTimer::timeout, [&] () {
|
QObject::connect(&waiter, &QTimer::timeout, [&] () {
|
||||||
if (ezcashd->atEnd()) {
|
if (ezcashd->atEnd() && ezcashd->processId() == 0) {
|
||||||
qDebug() << "Ended";
|
qDebug() << "Ended";
|
||||||
d.accept();
|
waiter.stop();
|
||||||
|
QTimer::singleShot(1000, [&]() { d.accept(); });
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Not ended";
|
qDebug() << "Not ended, continuing to wait...";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
waiter.start(1000);
|
waiter.start(1000);
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ private:
|
|||||||
|
|
||||||
// Current balance in the UI. If this number updates, then refresh the UI
|
// Current balance in the UI. If this number updates, then refresh the UI
|
||||||
QString currentBalance;
|
QString currentBalance;
|
||||||
|
|
||||||
// First time warning flag for no connection
|
// First time warning flag for no connection
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user