Browse Source

Fix a few issues related to starting and stopping hushd.

pull/45/head
FireMartZ 5 years ago
parent
commit
9d80672f62
  1. 27
      src/connection.cpp
  2. 2
      src/connection.h
  3. 5
      src/rpc.cpp
  4. 6
      src/rpc.h

27
src/connection.cpp

@ -178,6 +178,9 @@ void ConnectionLoader::createZcashConf() {
QFile file(confLocation);
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
main->logger->write("Could not create HUSH3.conf, returning");
QString explanation = QString() % QObject::tr("Could not create HUSH3.conf.");
this->showError(explanation);
return;
}
@ -342,6 +345,8 @@ bool ConnectionLoader::startEmbeddedZcashd() {
}
#elif defined(Q_OS_DARWIN)
auto zcashdProgram = appPath.absoluteFilePath("hushd");
#elif defined(Q_OS_WIN64)
auto zcashdProgram = appPath.absoluteFilePath("hushd.bat");
#else
//TODO: Not Linux + not darwin DOES NOT EQUAL windows!!!
auto zcashdProgram = appPath.absoluteFilePath("hushd");
@ -353,23 +358,25 @@ bool ConnectionLoader::startEmbeddedZcashd() {
return false;
}
ezcashd = new QProcess(main);
QObject::connect(ezcashd, &QProcess::started, [=] () {
ezcashd = std::shared_ptr<QProcess>(new QProcess(main));
QObject::connect(ezcashd.get(), &QProcess::started, [=] () {
qDebug() << "Embedded hushd started";
});
QObject::connect(ezcashd, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[=](int, QProcess::ExitStatus) {
//qDebug() << "hushd finished with code " << exitCode << "," << exitStatus;
QObject::connect(ezcashd.get(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "hushd finished with code " << exitCode << "," << exitStatus;
});
QObject::connect(ezcashd, &QProcess::errorOccurred, [&] (auto) {
//qDebug() << "Couldn't start hushd: " << error;
QObject::connect(ezcashd.get(), &QProcess::errorOccurred, [&] (QProcess::ProcessError error) {
qDebug() << "Couldn't start hushd: " << error;
});
QObject::connect(ezcashd, &QProcess::readyReadStandardError, [=]() {
auto output = ezcashd->readAllStandardError();
main->logger->write("hushd stderr:" + output);
std::weak_ptr<QProcess> weak_obj(ezcashd);
auto ptr_main(main);
QObject::connect(ezcashd.get(), &QProcess::readyReadStandardError, [weak_obj, ptr_main]() {
auto output = weak_obj.lock()->readAllStandardError();
ptr_main->logger->write("hushd stderr:" + output);
processStdErrOutput.append(output);
});

2
src/connection.h

@ -64,7 +64,7 @@ private:
void doRPCSetConnection(Connection* conn);
QProcess* ezcashd = nullptr;
std::shared_ptr<QProcess> ezcashd;
QDialog* d;
Ui_ConnectionDialog* connD;

5
src/rpc.cpp

@ -73,7 +73,7 @@ RPC::~RPC() {
delete conn;
}
void RPC::setEZcashd(QProcess* p) {
void RPC::setEZcashd(std::shared_ptr<QProcess> p) {
ezcashd = p;
if (ezcashd && ui->tabWidget->widget(4) == nullptr) {
@ -1140,7 +1140,8 @@ void RPC::shutdownZcashd() {
waitCount++;
if ((ezcashd->atEnd() && ezcashd->processId() == 0) ||
waitCount > 30 ||
ezcashd->state() == QProcess::NotRunning ||
waitCount > 30 ||
conn->config->zcashDaemon) { // If zcashd is daemon, then we don't have to do anything else
qDebug() << "Ended";
waiter.stop();

6
src/rpc.h

@ -38,8 +38,8 @@ public:
~RPC();
void setConnection(Connection* c);
void setEZcashd(QProcess* p);
const QProcess* getEZcashD() { return ezcashd; }
void setEZcashd(std::shared_ptr<QProcess> p);
const QProcess* getEZcashD() { return ezcashd.get(); }
void refresh(bool force = false);
@ -109,7 +109,7 @@ private:
void getTAddresses (const std::function<void(json)>& cb);
Connection* conn = nullptr;
QProcess* ezcashd = nullptr;
std::shared_ptr<QProcess> ezcashd = nullptr;
QList<UnspentOutput>* utxos = nullptr;
QMap<QString, double>* allBalances = nullptr;

Loading…
Cancel
Save