diff options
author | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2015-04-09 11:24:15 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2015-04-13 14:51:57 +0000 |
commit | 96cc8eec9b32f4e80c2d748687c485bc79133d39 (patch) | |
tree | 5902bb2cc6aa7e70070c46282169be3ae57a239f | |
parent | 95b481ea6dfa901c23b012085527769f9b5823c9 (diff) |
remove the "wonderful Windows notifier" from QProcess
Remove the 100 ms timer that was used to nudge QProcess to write data
to the child's stdin. Instead, react on the canWrite() signal of
QWindowsPipeWriter.
QProcess::writeData needs to call _q_canWrite via the event loop to
start the write operation. The socket notifier code was never in use on
Windows.
Task-number: QTBUG-45457
Change-Id: I99c956ba5f2169f80068eee206543ceb9788b2e0
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r-- | src/corelib/io/qprocess.cpp | 34 | ||||
-rw-r--r-- | src/corelib/io/qprocess.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qprocess_p.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 19 | ||||
-rw-r--r-- | src/corelib/io/qprocess_wince.cpp | 4 |
6 files changed, 30 insertions, 36 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 7d7cdef203..ead04791e5 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -36,6 +36,9 @@ #include <qdebug.h> #include <qdir.h> +#if defined(Q_OS_WIN) +#include <qtimer.h> +#endif #if defined QPROCESS_DEBUG #include <qstring.h> #include <ctype.h> @@ -819,7 +822,7 @@ QProcessPrivate::QProcessPrivate() emittedReadyRead = false; emittedBytesWritten = false; #ifdef Q_OS_WIN - notifier = 0; + stdinWriteTrigger = 0; processFinishedNotifier = 0; #endif // Q_OS_WIN } @@ -848,6 +851,10 @@ void QProcessPrivate::cleanup() delete pid; pid = 0; } + if (stdinWriteTrigger) { + delete stdinWriteTrigger; + stdinWriteTrigger = 0; + } if (processFinishedNotifier) { delete processFinishedNotifier; processFinishedNotifier = 0; @@ -878,12 +885,6 @@ void QProcessPrivate::cleanup() delete deathNotifier; deathNotifier = 0; } -#ifdef Q_OS_WIN - if (notifier) { - delete notifier; - notifier = 0; - } -#endif closeChannel(&stdoutChannel); closeChannel(&stderrChannel); closeChannel(&stdinChannel); @@ -1953,10 +1954,24 @@ qint64 QProcess::writeData(const char *data, qint64 len) return 0; } +#if defined(Q_OS_WIN) + if (!d->stdinWriteTrigger) { + d->stdinWriteTrigger = new QTimer; + d->stdinWriteTrigger->setSingleShot(true); + QObjectPrivate::connect(d->stdinWriteTrigger, &QTimer::timeout, + d, &QProcessPrivate::_q_canWrite); + } +#endif + if (len == 1) { d->stdinChannel.buffer.putChar(*data); +#ifdef Q_OS_WIN + if (!d->stdinWriteTrigger->isActive()) + d->stdinWriteTrigger->start(); +#else if (d->stdinChannel.notifier) d->stdinChannel.notifier->setEnabled(true); +#endif #if defined QPROCESS_DEBUG qDebug("QProcess::writeData(%p \"%s\", %lld) == 1 (written to buffer)", data, qt_prettyDebug(data, len, 16).constData(), len); @@ -1966,8 +1981,13 @@ qint64 QProcess::writeData(const char *data, qint64 len) char *dest = d->stdinChannel.buffer.reserve(len); memcpy(dest, data, len); +#ifdef Q_OS_WIN + if (!d->stdinWriteTrigger->isActive()) + d->stdinWriteTrigger->start(); +#else if (d->stdinChannel.notifier) d->stdinChannel.notifier->setEnabled(true); +#endif #if defined QPROCESS_DEBUG qDebug("QProcess::writeData(%p \"%s\", %lld) == %lld (written to buffer)", data, qt_prettyDebug(data, len, 16).constData(), len, len); diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index 65af469c18..54cf37b717 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -266,7 +266,6 @@ private: Q_PRIVATE_SLOT(d_func(), bool _q_canWrite()) Q_PRIVATE_SLOT(d_func(), bool _q_startupNotification()) Q_PRIVATE_SLOT(d_func(), bool _q_processDied()) - Q_PRIVATE_SLOT(d_func(), void _q_notified()) friend class QProcessManager; }; diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index 5654b404fe..f6bd64fb87 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -303,7 +303,6 @@ public: bool _q_canWrite(); bool _q_startupNotification(); bool _q_processDied(); - void _q_notified(); QProcess::ProcessChannel processChannel; QProcess::ProcessChannelMode processChannelMode; @@ -342,8 +341,7 @@ public: int forkfd; #ifdef Q_OS_WIN - // the wonderful windows notifier - QTimer *notifier; + QTimer *stdinWriteTrigger; QWinEventNotifier *processFinishedNotifier; #endif diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 46b557d6e0..69b631f7e7 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -1111,10 +1111,6 @@ bool QProcessPrivate::waitForDeadChild() return true; } -void QProcessPrivate::_q_notified() -{ -} - #if defined(QPROCESS_USE_SPAWN) bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid) { diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 563286e3e9..cef961ecbd 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -41,7 +41,6 @@ #include <qelapsedtimer.h> #include <qfileinfo.h> #include <qregexp.h> -#include <qtimer.h> #include <qwineventnotifier.h> #include <private/qthread_p.h> #include <qdebug.h> @@ -58,8 +57,6 @@ QT_BEGIN_NAMESPACE //#define QPROCESS_DEBUG -#define NOTIFYTIMEOUT 100 - static void qt_create_pipe(Q_PIPE *pipe, bool isInputPipe) { // Anomymous pipes do not support asynchronous I/O. Thus we @@ -543,9 +540,6 @@ void QProcessPrivate::startProcess() processFinishedNotifier = new QWinEventNotifier(pid->hProcess, q); QObject::connect(processFinishedNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_processDied())); processFinishedNotifier->setEnabled(true); - notifier = new QTimer(q); - QObject::connect(notifier, SIGNAL(timeout()), q, SLOT(_q_notified())); - notifier->start(NOTIFYTIMEOUT); } _q_startupNotification(); @@ -810,6 +804,8 @@ qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen) if (!stdinChannel.writer) { stdinChannel.writer = new QWindowsPipeWriter(stdinChannel.pipe[1], q); + QObjectPrivate::connect(stdinChannel.writer, &QWindowsPipeWriter::canWrite, + this, &QProcessPrivate::_q_canWrite); stdinChannel.writer->start(); } @@ -828,17 +824,6 @@ bool QProcessPrivate::waitForWrite(int msecs) return false; } -void QProcessPrivate::_q_notified() -{ - notifier->stop(); - - if (!stdinChannel.buffer.isEmpty() && (!stdinChannel.writer || stdinChannel.writer->waitForWrite(0))) - _q_canWrite(); - - if (processState != QProcess::NotRunning) - notifier->start(NOTIFYTIMEOUT); -} - bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDir, qint64 *pid) { QString args = qt_create_commandline(program, arguments); diff --git a/src/corelib/io/qprocess_wince.cpp b/src/corelib/io/qprocess_wince.cpp index bf19c81f25..53767758c2 100644 --- a/src/corelib/io/qprocess_wince.cpp +++ b/src/corelib/io/qprocess_wince.cpp @@ -288,10 +288,6 @@ bool QProcessPrivate::waitForWrite(int msecs) return false; } -void QProcessPrivate::_q_notified() -{ -} - bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDir, qint64 *pid) { Q_UNUSED(workingDir); |