summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2021-03-07 14:44:23 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2021-03-11 16:05:40 +0200
commit6bd61513290ef23783220b0e7507c4f03d5114e7 (patch)
treeb419789982671b98fb6758e5648a65b6a412e1ea /src/corelib/io/qprocess.cpp
parent5fa8f5df7bb722c5b7451229f5eecd13bd13326f (diff)
QProcess/Win: implement async closing of write channel
Instead of blocking in QProcessPrivate::closeWriteChannel(), we can handle a pending close in _q_canWrite() slot when there is no more data to write. Change-Id: I2a30789b6099a2ec075292348ebe33a11341bca3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io/qprocess.cpp')
-rw-r--r--src/corelib/io/qprocess.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index f03fc067cf..745c88e726 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -1097,8 +1097,13 @@ bool QProcessPrivate::_q_canReadStandardError()
bool QProcessPrivate::_q_canWrite()
{
if (writeBuffer.isEmpty()) {
+#ifdef Q_OS_WIN
+ if (stdinChannel.closed && pipeWriterBytesToWrite() == 0)
+ closeWriteChannel();
+#else
if (stdinChannel.notifier)
stdinChannel.notifier->setEnabled(false);
+#endif
#if defined QPROCESS_DEBUG
qDebug("QProcessPrivate::canWrite(), not writing anything (empty write buffer).");
#endif
@@ -1107,10 +1112,12 @@ bool QProcessPrivate::_q_canWrite()
const bool writeSucceeded = writeToStdin();
+#ifdef Q_OS_UNIX
if (writeBuffer.isEmpty() && stdinChannel.closed)
closeWriteChannel();
else if (stdinChannel.notifier)
stdinChannel.notifier->setEnabled(!writeBuffer.isEmpty());
+#endif
return writeSucceeded;
}
@@ -1211,11 +1218,6 @@ void QProcessPrivate::closeWriteChannel()
qDebug("QProcessPrivate::closeWriteChannel()");
#endif
-#ifdef Q_OS_WIN
- // ### Find a better fix, feeding the process little by little
- // instead.
- flushPipeWriter();
-#endif
closeChannel(&stdinChannel);
}
@@ -1373,7 +1375,7 @@ void QProcess::closeWriteChannel()
{
Q_D(QProcess);
d->stdinChannel.closed = true; // closing
- if (d->writeBuffer.isEmpty())
+ if (bytesToWrite() == 0)
d->closeWriteChannel();
}