diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2010-03-01 10:06:05 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2010-03-01 10:06:32 +0100 |
commit | a1fed931c45c81566fd3d806abcb39b7c7bffabd (patch) | |
tree | 7d163fbe9545b3fb2a3cc95e822e9e5fbaafa802 /src/libs/utils/synchronousprocess.h | |
parent | 1f940786fbd1e99441b91e071c242858e7439da2 (diff) |
VCS: Fix time-out handling for synchronous processes.
Introduce static utilities to Utils::SynchronousProcess
for synchronous processes that mimicks the handling
of Utils::SynchronousProcess (apply timeout after no
more data are available on stdout/stderr as opposed
to waitForFinished()).
Task-number: QTCREATORBUG-777
Diffstat (limited to 'src/libs/utils/synchronousprocess.h')
-rw-r--r-- | src/libs/utils/synchronousprocess.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libs/utils/synchronousprocess.h b/src/libs/utils/synchronousprocess.h index 8e7aa042f4a..bf8c033e01c 100644 --- a/src/libs/utils/synchronousprocess.h +++ b/src/libs/utils/synchronousprocess.h @@ -82,7 +82,12 @@ QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const SynchronousProcessRes * The stdOutBuffered(), stdErrBuffered() signals are emitted with complete * lines based on the '\n' marker if they are enabled using * stdOutBufferedSignalsEnabled()/setStdErrBufferedSignalsEnabled(). - * They would typically be used for log windows. */ + * They would typically be used for log windows. + * + * There is a timeout handling that takes effect after the last data have been + * read from stdout/stdin (as opposed to waitForFinished(), which measures time + * since it was invoked). It is thus also suitable for slow processes that continously + * output data (like version system operations). */ class QTCREATOR_UTILS_EXPORT SynchronousProcess : public QObject { @@ -91,7 +96,8 @@ public: SynchronousProcess(); virtual ~SynchronousProcess(); - /* Timeout for hanging processes (no reaction on stderr/stdout)*/ + /* Timeout for hanging processes (triggers after no more output + * occurs on stderr/stdout). */ void setTimeout(int timeoutMS); int timeout() const; @@ -118,6 +124,16 @@ public: SynchronousProcessResponse run(const QString &binary, const QStringList &args); + // Static helper for running a process synchronously in the foreground with timeout + // detection similar SynchronousProcess' handling (taking effect after no more output + // occurs on stderr/stdout as opposed to waitForFinished()). Returns false if a timeout + // occurs. Checking of the process' exit state/code still has to be done. + static bool readDataFromProcess(QProcess &p, int timeOutMS, + QByteArray *stdOut = 0, QByteArray *stdErr = 0); + // Stop a process by first calling terminate() (allowing for signal handling) and + // then kill(). + static bool stopProcess(QProcess &p); + // Helpers to find binaries. Do not use it for other path variables // and file types. static QString locateBinary(const QString &binary); |