Move the QProcessPrivate channel buffers into QProcessPrivate::Channel
Simplifies the code. Change-Id: I70b26af69332f364d856042f114c37a70504d66f Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
This commit is contained in:
parent
da5dea807f
commit
29f92d112a
@ -916,7 +916,7 @@ bool QProcessPrivate::_q_canReadStandardOutput()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ptr = outputReadBuffer.reserve(available);
|
char *ptr = stdoutChannel.buffer.reserve(available);
|
||||||
qint64 readBytes = readFromStdout(ptr, available);
|
qint64 readBytes = readFromStdout(ptr, available);
|
||||||
if (readBytes == -1) {
|
if (readBytes == -1) {
|
||||||
processError = QProcess::ReadError;
|
processError = QProcess::ReadError;
|
||||||
@ -933,11 +933,11 @@ bool QProcessPrivate::_q_canReadStandardOutput()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (stdoutChannel.closed) {
|
if (stdoutChannel.closed) {
|
||||||
outputReadBuffer.chop(readBytes);
|
stdoutChannel.buffer.chop(readBytes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
outputReadBuffer.chop(available - readBytes);
|
stdoutChannel.buffer.chop(available - readBytes);
|
||||||
|
|
||||||
bool didRead = false;
|
bool didRead = false;
|
||||||
if (readBytes == 0) {
|
if (readBytes == 0) {
|
||||||
@ -969,7 +969,7 @@ bool QProcessPrivate::_q_canReadStandardError()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ptr = errorReadBuffer.reserve(available);
|
char *ptr = stderrChannel.buffer.reserve(available);
|
||||||
qint64 readBytes = readFromStderr(ptr, available);
|
qint64 readBytes = readFromStderr(ptr, available);
|
||||||
if (readBytes == -1) {
|
if (readBytes == -1) {
|
||||||
processError = QProcess::ReadError;
|
processError = QProcess::ReadError;
|
||||||
@ -978,11 +978,11 @@ bool QProcessPrivate::_q_canReadStandardError()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (stderrChannel.closed) {
|
if (stderrChannel.closed) {
|
||||||
errorReadBuffer.chop(readBytes);
|
stderrChannel.buffer.chop(readBytes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorReadBuffer.chop(available - readBytes);
|
stderrChannel.buffer.chop(available - readBytes);
|
||||||
|
|
||||||
bool didRead = false;
|
bool didRead = false;
|
||||||
if (readBytes == 0) {
|
if (readBytes == 0) {
|
||||||
@ -1009,15 +1009,15 @@ bool QProcessPrivate::_q_canWrite()
|
|||||||
if (stdinChannel.notifier)
|
if (stdinChannel.notifier)
|
||||||
stdinChannel.notifier->setEnabled(false);
|
stdinChannel.notifier->setEnabled(false);
|
||||||
|
|
||||||
if (writeBuffer.isEmpty()) {
|
if (stdinChannel.buffer.isEmpty()) {
|
||||||
#if defined QPROCESS_DEBUG
|
#if defined QPROCESS_DEBUG
|
||||||
qDebug("QProcessPrivate::canWrite(), not writing anything (empty write buffer).");
|
qDebug("QProcessPrivate::canWrite(), not writing anything (empty write buffer).");
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 written = writeToStdin(writeBuffer.readPointer(),
|
qint64 written = writeToStdin(stdinChannel.buffer.readPointer(),
|
||||||
writeBuffer.nextDataBlockSize());
|
stdinChannel.buffer.nextDataBlockSize());
|
||||||
if (written < 0) {
|
if (written < 0) {
|
||||||
destroyChannel(&stdinChannel);
|
destroyChannel(&stdinChannel);
|
||||||
processError = QProcess::WriteError;
|
processError = QProcess::WriteError;
|
||||||
@ -1031,16 +1031,16 @@ bool QProcessPrivate::_q_canWrite()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (written != 0) {
|
if (written != 0) {
|
||||||
writeBuffer.free(written);
|
stdinChannel.buffer.free(written);
|
||||||
if (!emittedBytesWritten) {
|
if (!emittedBytesWritten) {
|
||||||
emittedBytesWritten = true;
|
emittedBytesWritten = true;
|
||||||
emit q->bytesWritten(written);
|
emit q->bytesWritten(written);
|
||||||
emittedBytesWritten = false;
|
emittedBytesWritten = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stdinChannel.notifier && !writeBuffer.isEmpty())
|
if (stdinChannel.notifier && !stdinChannel.buffer.isEmpty())
|
||||||
stdinChannel.notifier->setEnabled(true);
|
stdinChannel.notifier->setEnabled(true);
|
||||||
if (writeBuffer.isEmpty() && stdinChannel.closed)
|
if (stdinChannel.buffer.isEmpty() && stdinChannel.closed)
|
||||||
closeWriteChannel();
|
closeWriteChannel();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1308,10 +1308,10 @@ void QProcess::setReadChannel(ProcessChannel channel)
|
|||||||
QByteArray buf = d->buffer.readAll();
|
QByteArray buf = d->buffer.readAll();
|
||||||
if (d->processChannel == QProcess::StandardOutput) {
|
if (d->processChannel == QProcess::StandardOutput) {
|
||||||
for (int i = buf.size() - 1; i >= 0; --i)
|
for (int i = buf.size() - 1; i >= 0; --i)
|
||||||
d->outputReadBuffer.ungetChar(buf.at(i));
|
d->stdoutChannel.buffer.ungetChar(buf.at(i));
|
||||||
} else {
|
} else {
|
||||||
for (int i = buf.size() - 1; i >= 0; --i)
|
for (int i = buf.size() - 1; i >= 0; --i)
|
||||||
d->errorReadBuffer.ungetChar(buf.at(i));
|
d->stderrChannel.buffer.ungetChar(buf.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d->processChannel = channel;
|
d->processChannel = channel;
|
||||||
@ -1359,7 +1359,7 @@ void QProcess::closeWriteChannel()
|
|||||||
{
|
{
|
||||||
Q_D(QProcess);
|
Q_D(QProcess);
|
||||||
d->stdinChannel.closed = true; // closing
|
d->stdinChannel.closed = true; // closing
|
||||||
if (d->writeBuffer.isEmpty())
|
if (d->stdinChannel.buffer.isEmpty())
|
||||||
d->closeWriteChannel();
|
d->closeWriteChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1589,8 +1589,8 @@ bool QProcess::canReadLine() const
|
|||||||
{
|
{
|
||||||
Q_D(const QProcess);
|
Q_D(const QProcess);
|
||||||
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
||||||
? &d->errorReadBuffer
|
? &d->stderrChannel.buffer
|
||||||
: &d->outputReadBuffer;
|
: &d->stdoutChannel.buffer;
|
||||||
return readBuffer->canReadLine() || QIODevice::canReadLine();
|
return readBuffer->canReadLine() || QIODevice::canReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1618,8 +1618,8 @@ bool QProcess::atEnd() const
|
|||||||
{
|
{
|
||||||
Q_D(const QProcess);
|
Q_D(const QProcess);
|
||||||
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
||||||
? &d->errorReadBuffer
|
? &d->stderrChannel.buffer
|
||||||
: &d->outputReadBuffer;
|
: &d->stdoutChannel.buffer;
|
||||||
return QIODevice::atEnd() && (!isOpen() || readBuffer->isEmpty());
|
return QIODevice::atEnd() && (!isOpen() || readBuffer->isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1636,8 +1636,8 @@ qint64 QProcess::bytesAvailable() const
|
|||||||
{
|
{
|
||||||
Q_D(const QProcess);
|
Q_D(const QProcess);
|
||||||
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
||||||
? &d->errorReadBuffer
|
? &d->stderrChannel.buffer
|
||||||
: &d->outputReadBuffer;
|
: &d->stdoutChannel.buffer;
|
||||||
#if defined QPROCESS_DEBUG
|
#if defined QPROCESS_DEBUG
|
||||||
qDebug("QProcess::bytesAvailable() == %i (%s)", readBuffer->size(),
|
qDebug("QProcess::bytesAvailable() == %i (%s)", readBuffer->size(),
|
||||||
(d->processChannel == QProcess::StandardError) ? "stderr" : "stdout");
|
(d->processChannel == QProcess::StandardError) ? "stderr" : "stdout");
|
||||||
@ -1650,7 +1650,7 @@ qint64 QProcess::bytesAvailable() const
|
|||||||
qint64 QProcess::bytesToWrite() const
|
qint64 QProcess::bytesToWrite() const
|
||||||
{
|
{
|
||||||
Q_D(const QProcess);
|
Q_D(const QProcess);
|
||||||
qint64 size = d->writeBuffer.size();
|
qint64 size = d->stdinChannel.buffer.size();
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
size += d->pipeWriterBytesToWrite();
|
size += d->pipeWriterBytesToWrite();
|
||||||
#endif
|
#endif
|
||||||
@ -1897,8 +1897,8 @@ qint64 QProcess::readData(char *data, qint64 maxlen)
|
|||||||
if (!maxlen)
|
if (!maxlen)
|
||||||
return 0;
|
return 0;
|
||||||
QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
|
||||||
? &d->errorReadBuffer
|
? &d->stderrChannel.buffer
|
||||||
: &d->outputReadBuffer;
|
: &d->stdoutChannel.buffer;
|
||||||
|
|
||||||
if (maxlen == 1 && !readBuffer->isEmpty()) {
|
if (maxlen == 1 && !readBuffer->isEmpty()) {
|
||||||
int c = readBuffer->getChar();
|
int c = readBuffer->getChar();
|
||||||
@ -1961,7 +1961,7 @@ qint64 QProcess::writeData(const char *data, qint64 len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (len == 1) {
|
if (len == 1) {
|
||||||
d->writeBuffer.putChar(*data);
|
d->stdinChannel.buffer.putChar(*data);
|
||||||
if (d->stdinChannel.notifier)
|
if (d->stdinChannel.notifier)
|
||||||
d->stdinChannel.notifier->setEnabled(true);
|
d->stdinChannel.notifier->setEnabled(true);
|
||||||
#if defined QPROCESS_DEBUG
|
#if defined QPROCESS_DEBUG
|
||||||
@ -1971,7 +1971,7 @@ qint64 QProcess::writeData(const char *data, qint64 len)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *dest = d->writeBuffer.reserve(len);
|
char *dest = d->stdinChannel.buffer.reserve(len);
|
||||||
memcpy(dest, data, len);
|
memcpy(dest, data, len);
|
||||||
if (d->stdinChannel.notifier)
|
if (d->stdinChannel.notifier)
|
||||||
d->stdinChannel.notifier->setEnabled(true);
|
d->stdinChannel.notifier->setEnabled(true);
|
||||||
@ -2112,8 +2112,8 @@ void QProcessPrivate::start(QIODevice::OpenMode mode)
|
|||||||
qDebug() << "QProcess::start(" << program << ',' << arguments << ',' << mode << ')';
|
qDebug() << "QProcess::start(" << program << ',' << arguments << ',' << mode << ')';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
outputReadBuffer.clear();
|
stdoutChannel.buffer.clear();
|
||||||
errorReadBuffer.clear();
|
stderrChannel.buffer.clear();
|
||||||
|
|
||||||
if (stdinChannel.type != QProcessPrivate::Channel::Normal)
|
if (stdinChannel.type != QProcessPrivate::Channel::Normal)
|
||||||
mode &= ~QIODevice::WriteOnly; // not open for writing
|
mode &= ~QIODevice::WriteOnly; // not open for writing
|
||||||
|
@ -282,6 +282,7 @@ public:
|
|||||||
QString file;
|
QString file;
|
||||||
QProcessPrivate *process;
|
QProcessPrivate *process;
|
||||||
QSocketNotifier *notifier;
|
QSocketNotifier *notifier;
|
||||||
|
QRingBuffer buffer;
|
||||||
Q_PIPE pipe[2];
|
Q_PIPE pipe[2];
|
||||||
|
|
||||||
unsigned type : 2;
|
unsigned type : 2;
|
||||||
@ -326,10 +327,6 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
QProcessEnvironment environment;
|
QProcessEnvironment environment;
|
||||||
|
|
||||||
QRingBuffer outputReadBuffer;
|
|
||||||
QRingBuffer errorReadBuffer;
|
|
||||||
QRingBuffer writeBuffer;
|
|
||||||
|
|
||||||
Q_PIPE childStartedPipe[2];
|
Q_PIPE childStartedPipe[2];
|
||||||
Q_PIPE deathPipe[2];
|
Q_PIPE deathPipe[2];
|
||||||
void destroyPipe(Q_PIPE pipe[2]);
|
void destroyPipe(Q_PIPE pipe[2]);
|
||||||
|
@ -1126,7 +1126,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
|
|||||||
if (stderrChannel.pipe[0] != -1)
|
if (stderrChannel.pipe[0] != -1)
|
||||||
add_fd(nfds, stderrChannel.pipe[0], &fdread);
|
add_fd(nfds, stderrChannel.pipe[0], &fdread);
|
||||||
|
|
||||||
if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
|
if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1)
|
||||||
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
|
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
|
||||||
|
|
||||||
int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
|
int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
|
||||||
@ -1188,7 +1188,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
|
|||||||
QList<QSocketNotifier *> notifiers = defaultNotifiers();
|
QList<QSocketNotifier *> notifiers = defaultNotifiers();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (!writeBuffer.isEmpty()) {
|
while (!stdinChannel.buffer.isEmpty()) {
|
||||||
fd_set fdread;
|
fd_set fdread;
|
||||||
fd_set fdwrite;
|
fd_set fdwrite;
|
||||||
|
|
||||||
@ -1207,7 +1207,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
|
|||||||
add_fd(nfds, stderrChannel.pipe[0], &fdread);
|
add_fd(nfds, stderrChannel.pipe[0], &fdread);
|
||||||
|
|
||||||
|
|
||||||
if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
|
if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1)
|
||||||
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
|
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
|
||||||
|
|
||||||
int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
|
int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
|
||||||
@ -1282,7 +1282,7 @@ bool QProcessPrivate::waitForFinished(int msecs)
|
|||||||
if (processState == QProcess::Running)
|
if (processState == QProcess::Running)
|
||||||
add_fd(nfds, deathPipe[0], &fdread);
|
add_fd(nfds, deathPipe[0], &fdread);
|
||||||
|
|
||||||
if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
|
if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1)
|
||||||
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
|
add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
|
||||||
|
|
||||||
int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
|
int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
|
||||||
|
@ -690,7 +690,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs)
|
|||||||
QIncrementalSleepTimer timer(msecs);
|
QIncrementalSleepTimer timer(msecs);
|
||||||
|
|
||||||
forever {
|
forever {
|
||||||
if (!writeBuffer.isEmpty() && !_q_canWrite())
|
if (!stdinChannel.buffer.isEmpty() && !_q_canWrite())
|
||||||
return false;
|
return false;
|
||||||
if (pipeWriter && pipeWriter->waitForWrite(0))
|
if (pipeWriter && pipeWriter->waitForWrite(0))
|
||||||
timer.resetIncrements();
|
timer.resetIncrements();
|
||||||
@ -731,7 +731,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs)
|
|||||||
|
|
||||||
// If we don't have pending data, and our write buffer is
|
// If we don't have pending data, and our write buffer is
|
||||||
// empty, we fail.
|
// empty, we fail.
|
||||||
if (!pendingDataInPipe && writeBuffer.isEmpty())
|
if (!pendingDataInPipe && stdinChannel.buffer.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If we don't have pending data and we do have data in our
|
// If we don't have pending data and we do have data in our
|
||||||
@ -795,7 +795,7 @@ bool QProcessPrivate::waitForFinished(int msecs)
|
|||||||
QIncrementalSleepTimer timer(msecs);
|
QIncrementalSleepTimer timer(msecs);
|
||||||
|
|
||||||
forever {
|
forever {
|
||||||
if (!writeBuffer.isEmpty() && !_q_canWrite())
|
if (!stdinChannel.buffer.isEmpty() && !_q_canWrite())
|
||||||
return false;
|
return false;
|
||||||
if (pipeWriter && pipeWriter->waitForWrite(0))
|
if (pipeWriter && pipeWriter->waitForWrite(0))
|
||||||
timer.resetIncrements();
|
timer.resetIncrements();
|
||||||
@ -875,7 +875,7 @@ void QProcessPrivate::_q_notified()
|
|||||||
{
|
{
|
||||||
notifier->stop();
|
notifier->stop();
|
||||||
|
|
||||||
if (!writeBuffer.isEmpty() && (!pipeWriter || pipeWriter->waitForWrite(0)))
|
if (!stdinChannel.buffer.isEmpty() && (!pipeWriter || pipeWriter->waitForWrite(0)))
|
||||||
_q_canWrite();
|
_q_canWrite();
|
||||||
|
|
||||||
if (processState != QProcess::NotRunning)
|
if (processState != QProcess::NotRunning)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user