QAbstractSocket: Enable readNotifier on read from buffer
authorMartin Petersson <Martin.Petersson@nokia.com>
Mon, 4 Jun 2012 14:34:13 +0000 (16:34 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 26 Jun 2012 09:32:21 +0000 (11:32 +0200)
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 <thiago.macieira@intel.com>
src/corelib/io/qfiledevice.cpp
src/corelib/io/qiodevice.cpp
src/corelib/io/qprocess.cpp
src/network/socket/qabstractsocket.cpp
src/network/socket/qlocalsocket_win.cpp

index e1f1db9..fc1bc60 100644 (file)
@@ -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;
index 03bf59e..a60aee1 100644 (file)
@@ -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()
 */
 
index de8e3d4..7228cec 100644 (file)
@@ -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;
index 3959419..8f290f6 100644 (file)
@@ -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
index 35b0130..90c8fce 100644 (file)
@@ -200,6 +200,9 @@ qint64 QLocalSocket::readData(char *data, qint64 maxSize)
 {
     Q_D(QLocalSocket);
 
+    if (!maxSize)
+        return 0;
+
     return d->pipeReader->read(data, maxSize);
 }