From 1ce203d05a952f039105d30968daf2eacae66be8 Mon Sep 17 00:00:00 2001 From: Martin Petersson Date: Mon, 4 Jun 2012 16:34:13 +0200 Subject: QAbstractSocket: Enable readNotifier on read from buffer This is needed for the QSslSocket. When we read on that socket we will only read from the QIODevice buffer to get the unencrypted data. So when the readNotifier has been turned off on the plainsocket there is nothing to trigger it to be turned on again. This will add a readData with zero size when we have read everything from the buffer. This is so that we get a call into the socket to check if the readNotifier should be turned on again. Change-Id: I3b63e33de007db823e964480903186eb1b8caac2 Reviewed-by: Thiago Macieira --- src/corelib/io/qfiledevice.cpp | 2 ++ src/corelib/io/qiodevice.cpp | 16 +++++++++++++++- src/corelib/io/qprocess.cpp | 2 ++ src/network/socket/qabstractsocket.cpp | 7 +++++++ src/network/socket/qlocalsocket_win.cpp | 3 +++ 5 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index e1f1db9ead..fc1bc6009a 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -459,6 +459,8 @@ qint64 QFileDevice::readLineData(char *data, qint64 maxlen) qint64 QFileDevice::readData(char *data, qint64 len) { Q_D(QFileDevice); + if (!len) + return 0; unsetError(); if (!d->ensureFlushed()) return -1; diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 03bf59ed9d..a60aee1ebe 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -772,6 +772,8 @@ qint64 QIODevice::read(char *data, qint64 maxSize) printf("%p \tread 0x%hhx (%c) returning 1 (shortcut)\n", this, int(c), isprint(c) ? c : '?'); #endif + if (d->buffer.isEmpty()) + readData(data, 0); return qint64(1); } } @@ -786,8 +788,11 @@ qint64 QIODevice::read(char *data, qint64 maxSize) *d->pPos += lastReadChunkSize; readSoFar += lastReadChunkSize; // fast exit when satisfied by buffer - if (lastReadChunkSize == maxSize && !(d->openMode & Text)) + if (lastReadChunkSize == maxSize && !(d->openMode & Text)) { + if (d->buffer.isEmpty()) + readData(data, 0); return readSoFar; + } data += lastReadChunkSize; maxSize -= lastReadChunkSize; @@ -906,6 +911,10 @@ qint64 QIODevice::read(char *data, qint64 maxSize) int(readSoFar), int(d->pos), d->buffer.size()); debugBinaryString(data - readSoFar, readSoFar); #endif + + if (d->buffer.isEmpty()) + readData(data, 0); + return readSoFar; } @@ -1083,6 +1092,8 @@ qint64 QIODevice::readLine(char *data, qint64 maxSize) qint64 readSoFar = 0; if (!d->buffer.isEmpty()) { readSoFar = d->buffer.readLine(data, maxSize); + if (d->buffer.isEmpty()) + readData(data,0); if (!sequential) d->pos += readSoFar; #if defined QIODEVICE_DEBUG @@ -1622,6 +1633,9 @@ QString QIODevice::errorString() const all the requested information was read and therefore does not retry reading if there was a problem. + This function will be called with maxSize 0 when the device is + buffered and the buffer was emptied by a call to read(). + \sa read(), readLine(), writeData() */ diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index de8e3d4b49..7228ceca78 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1774,6 +1774,8 @@ void QProcess::setupChildProcess() qint64 QProcess::readData(char *data, qint64 maxlen) { Q_D(QProcess); + if (!maxlen) + return 0; QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError) ? &d->errorReadBuffer : &d->outputReadBuffer; diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 3959419fed..8f290f6e2f 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -2324,6 +2324,13 @@ qint64 QAbstractSocket::readData(char *data, qint64 maxSize) { Q_D(QAbstractSocket); + // Check if the read notifier can be enabled again. + if (d->socketEngine && !d->socketEngine->isReadNotificationEnabled() && d->socketEngine->isValid()) + d->socketEngine->setReadNotificationEnabled(true); + + if (!maxSize) + return 0; + // This is for a buffered QTcpSocket if (d->isBuffered && d->buffer.isEmpty()) // if we're still connected, return 0 indicating there may be more data in the future diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index 35b0130afc..90c8fcec1e 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -200,6 +200,9 @@ qint64 QLocalSocket::readData(char *data, qint64 maxSize) { Q_D(QLocalSocket); + if (!maxSize) + return 0; + return d->pipeReader->read(data, maxSize); } -- cgit v1.2.3