Преглед на файлове

Merge branch 'develop' of git.rwth-aachen.de:tobias.wach/ccats into develop

deleteme
Jonas Pflanzer преди 5 години
родител
ревизия
0ce25ea84d
променени са 2 файла, в които са добавени 8 реда и са изтрити 4 реда
  1. 7 3
      gui/src/qmlhandler.cpp
  2. 1 1
      gui/src/qmlhandler.h

+ 7 - 3
gui/src/qmlhandler.cpp

@@ -68,8 +68,7 @@ void QMLHandler::reopenCLI(QString ip) {
 
   close(outpipefd[0]);
   close(inpipefd[1]);
-
-  std::thread(&QMLHandler::readPipeLoop, this).detach();
+  std::thread(&QMLHandler::readPipeLoop, this, pid).detach();
 }
 
 std::vector<std::string> tokenizeByNewlines(std::string in) {
@@ -212,7 +211,7 @@ void QMLHandler::handleJSON(string buffer) {
 // If will read the Input Pipe, which containts the string that get printed
 // on stdout by the CLI/Server, and calls handleJSON with the read content
 // one it reads a newline.
-void QMLHandler::readPipeLoop() {
+void QMLHandler::readPipeLoop(pid_t childid) {
   unsigned int readOffset = 0;
   unsigned int pollCount = 0;
   struct pollfd inPipeStatus;
@@ -245,6 +244,11 @@ void QMLHandler::readPipeLoop() {
       memset(buf, 0, 1025);
       pollCount = 0;
       readOffset = 0;
+      if (waitpid(childid, NULL, WNOHANG)) {
+        // nonzero means error or childid has changed state
+        // for us that means child has exited -> CLI is dead
+        break;
+      }
     }
 
     // Fixme

+ 1 - 1
gui/src/qmlhandler.h

@@ -14,7 +14,7 @@ class QMLHandler : public QObject {
 
 private:
   void handleJSON(std::string buffer);
-  void readPipeLoop();
+  void readPipeLoop(pid_t childid);
   void reopenCLI(QString ip);
   void closeCLI();