From 22939e1d45883ac4e2c3a9690e11f7f09eda9242 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sat, 14 May 2016 22:11:23 +0200 Subject: Fix handling of QUIT-Message before HELLO-response in ProcessManager client --- src/ProcessManager.cpp | 53 +++++++++++++++++++++++++++++++++++--------------- src/ProcessManager.hpp | 1 + 2 files changed, 38 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ProcessManager.cpp b/src/ProcessManager.cpp index 6d2efe8..d0dbbf8 100644 --- a/src/ProcessManager.cpp +++ b/src/ProcessManager.cpp @@ -1,4 +1,5 @@ #include "ProcessManager.hpp" +#include #include #include @@ -43,15 +44,27 @@ ProcessManager::ProcessManager(const QString &newPrefix, const QString &newId, b return; } qDebug() << "Opened ctrlout"; - if(ctrlOut.readLine() != "HELLO\n") + + ctrlOut.waitForReadyRead(-1); + + int bytesAvailable = 0; + ioctl(ctrlOut.handle(), FIONREAD, &bytesAvailable); // QFile::bytesAvailable always returns 0 on fifos + + while(bytesAvailable > 0) + { + processCtrlMessage(QString::fromUtf8(ctrlOut.readLine())); + ioctl(ctrlOut.handle(), FIONREAD, &bytesAvailable); + } + + if(!ok) { qDebug() << "not HELLO"; return; } - qDebug() << "HELLO"; + ctrlOutNotifier = new QSocketNotifier(ctrlOut.handle(), QSocketNotifier::Read, this); connect(ctrlOutNotifier, SIGNAL(activated(int)), this, SLOT(ctrlOutReadyRead())); - ok = true; + if(reattaching) { ctrlIn.write("STATUS\n"); @@ -180,19 +193,7 @@ QString ProcessManager::ID() void ProcessManager::ctrlOutReadyRead() { - QString what = QString::fromUtf8(ctrlOut.readLine()); - QRegExp quitExp("^QUIT: (\\d+)\n"); - if(quitExp.exactMatch(what)) - { - exitCode = quitExp.cap(1).toInt(); - running = false; - stdOut.close(); - stdErr.close(); - stdIn.close(); - DELETE_SAVE(stdOutNotifier); - DELETE_SAVE(stdErrNotifier); - emit finished(exitCode); - } + processCtrlMessage(QString::fromUtf8(ctrlOut.readLine())); } void ProcessManager::_stdOutReadyRead() @@ -243,3 +244,23 @@ bool ProcessManager::connectToIO() return true; } +void ProcessManager::processCtrlMessage(const QString& message) +{ + QRegExp quitExp("^QUIT: (\\d+)\n"); + if(quitExp.exactMatch(message)) + { + exitCode = quitExp.cap(1).toInt(); + running = false; + stdOut.close(); + stdErr.close(); + stdIn.close(); + DELETE_SAVE(stdOutNotifier); + DELETE_SAVE(stdErrNotifier); + emit finished(exitCode); + } + else if(message == "HELLO\n") + { + ok = true; + } +} + diff --git a/src/ProcessManager.hpp b/src/ProcessManager.hpp index 85c05a2..2d64168 100644 --- a/src/ProcessManager.hpp +++ b/src/ProcessManager.hpp @@ -69,4 +69,5 @@ private: int exitCode = 0; bool connectToIO(); + void processCtrlMessage(const QString& message); }; -- cgit v1.2.3-54-g00ecf