From 3ccfc351fdcbb117e2872229382e45a929dac62a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 5 Jun 2014 16:44:07 -0700 Subject: QProcess: Handle spurious socket notifications for stdout and stderr On Unix systems where the GUI event dispatcher uses a notification system for socket notifiers that is out of band compared to select(), it's possible for the QSocketNotifier to activate after the pipe has been read from. When that happened, the ioctl(2) call with FIONREAD might return 0 bytes available, which we interpreted to mean EOF. Instead of doing that, always try to read at least one byte and examine the returned byte count from read(2). If it returns 0, that's a real EOF; if it returns -1 EWOULDBLOCK, we simply ignore the situation. That's the case on OS X: the Cocoa event dispatcher uses CFSocket to get notifications and those use kevent (and, apparently, an auxiliary thread) instead of an in-thread select() or poll(). That means the event loop would activate the QSocketNotifier even though there is nothing to be read. Task-number: QTBUG-39488 Change-Id: I1a58b5b1db7a47034fb36a78a005ebff96290efb Reviewed-by: Oswald Buddenhagen --- src/network/socket/qlocalsocket_win.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/network') diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index 96c6c0f6ea..6fef819eee 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -202,7 +202,17 @@ qint64 QLocalSocket::readData(char *data, qint64 maxSize) if (!maxSize) return 0; - return d->pipeReader->read(data, maxSize); + qint64 ret = d->pipeReader->read(data, maxSize); + + // QWindowsPipeReader::read() returns error codes that don't match what we need + switch (ret) { + case 0: // EOF -> transform to error + return -1; + case -2: // EWOULDBLOCK -> no error, just no bytes + return 0; + default: + return ret; + } } qint64 QLocalSocket::writeData(const char *data, qint64 maxSize) -- cgit v1.2.3