瀏覽代碼

fix thread spawning on refused connection

Missingmew 5 年之前
父節點
當前提交
4247dd59cd
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5 3
      gui/src/qmlhandler.cpp

+ 5 - 3
gui/src/qmlhandler.cpp

@@ -33,6 +33,7 @@ QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
 void QMLHandler::closeCLI() {
   close(outpipefd[1]);
   close(inpipefd[0]);
+  _CLI_RUNNING = false;
 }
 
 void QMLHandler::reopenCLI(QString ip) {
@@ -60,11 +61,12 @@ void QMLHandler::reopenCLI(QString ip) {
     execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(),
           "--machine", (char *)NULL);
 
-    _CLI_RUNNING = true;
 
     exit(1);
   }
 
+  _CLI_RUNNING = true;
+  
   close(outpipefd[0]);
   close(inpipefd[1]);
 
@@ -138,7 +140,7 @@ void QMLHandler::handleJSON(string buffer) {
     if (root["accept"].asBool()) {
     } else {
       emit ipPopupSetStatus(root["error"].asString().c_str());
-      reopenCLI(_IP);
+      closeCLI();
     }
   }
 
@@ -220,7 +222,7 @@ void QMLHandler::readPipeLoop() {
   vector<string> inputs;
   string pipeInput;
 
-  while (programActive) {
+  while (programActive && _CLI_RUNNING) {
     inputs = vector<string>();
     poll(&inPipeStatus, 1, 100);