diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2016-05-14 22:11:23 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2016-05-14 22:11:23 +0200 |
| commit | 22939e1d45883ac4e2c3a9690e11f7f09eda9242 (patch) | |
| tree | ec50ec2d45dd154c6799599f24f816fb4e98d535 /src/ProcessManager.cpp | |
| parent | 9adbb5d7e5475670c4e0f1b1dbf41257ba0811a8 (diff) | |
| download | manager-22939e1d45883ac4e2c3a9690e11f7f09eda9242.tar.gz manager-22939e1d45883ac4e2c3a9690e11f7f09eda9242.zip | |
Fix handling of QUIT-Message before HELLO-response in ProcessManager
client
Diffstat (limited to 'src/ProcessManager.cpp')
| -rw-r--r-- | src/ProcessManager.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
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 <sys/ioctl.h> #include <QProcess> #include <QDebug> @@ -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; + } +} + |
