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 <thiago.macieira@intel.com>
This commit is contained in:
Martin Petersson 2012-06-04 16:34:13 +02:00 committed by Qt by Nokia
parent bf6897edb0
commit 1ce203d05a
5 changed files with 29 additions and 1 deletions

View 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;

View 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()
*/

View 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;

View 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

View 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);
}