From 222fb565e28d5ba7f402755762c6a5df6ffcdd37 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 11:31:43 +0100 Subject: move POSIX-specific debug to qprocess_unix.cpp Merge-request: 997 Reviewed-by: Olivier Goffart --- src/corelib/io/qprocess.cpp | 3 --- src/corelib/io/qprocess_unix.cpp | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 739ac4d..da53014 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -963,9 +963,6 @@ bool QProcessPrivate::_q_canWrite() destroyPipe(stdinChannel.pipe); processError = QProcess::WriteError; q->setErrorString(QProcess::tr("Error writing to process")); -#if defined(QPROCESS_DEBUG) && !defined(Q_OS_WINCE) - qDebug("QProcessPrivate::canWrite(), failed to write (%s)", strerror(errno)); -#endif emit q->error(processError); return false; } diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index e52d132..0d5464e 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -866,6 +866,8 @@ qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen) #if defined QPROCESS_DEBUG qDebug("QProcessPrivate::writeToStdin(%p \"%s\", %lld) == %lld", data, qt_prettyDebug(data, maxlen, 16).constData(), maxlen, written); + if (written == -1) + qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qt_error_string(errno)); #endif return written; } -- cgit v0.12 From 7f2e9e43234a112e845568a4329a869975f73a21 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 11 Jan 2011 11:31:44 +0100 Subject: handle O_NONBLOCK'ed pipes specific error on write() according to the write(2) docs: When write requests greater than {PIPE_BUF} bytes to a pipe that has available space at least 1 byte, if O_NONBLOCK is set, write transfers what it can and returns the number of bytes written. When write requests of {PIPE_BUF} or less bytes to a pipe that has no enough space, or write requests for greater than {PIPE_BUF} bytes to a pipe that has no space, if O_NONBLOCK is set, write returns -1 and sets errno to EAGAIN. Merge-request: 997 Reviewed-by: Olivier Goffart --- src/corelib/io/qprocess.cpp | 12 +++++++----- src/corelib/io/qprocess_unix.cpp | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index da53014..1522f8e 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -971,11 +971,13 @@ bool QProcessPrivate::_q_canWrite() qDebug("QProcessPrivate::canWrite(), wrote %d bytes to the process input", int(written)); #endif - writeBuffer.free(written); - if (!emittedBytesWritten) { - emittedBytesWritten = true; - emit q->bytesWritten(written); - emittedBytesWritten = false; + if (written != 0) { + writeBuffer.free(written); + if (!emittedBytesWritten) { + emittedBytesWritten = true; + emit q->bytesWritten(written); + emittedBytesWritten = false; + } } if (stdinChannel.notifier && !writeBuffer.isEmpty()) stdinChannel.notifier->setEnabled(true); diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 0d5464e..299280e 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -869,6 +869,11 @@ qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen) if (written == -1) qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qt_error_string(errno)); #endif + // If the O_NONBLOCK flag is set and If some data can be written without blocking + // the process, write() will transfer what it can and return the number of bytes written. + // Otherwise, it will return -1 and set errno to EAGAIN + if (written == -1 && errno == EAGAIN) + written = 0; return written; } -- cgit v0.12