From 02532ec80375c686503c4250c6ad6bb211515ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 15 Apr 2010 19:02:34 +0200 Subject: Fix QSslSocket::constructing autotest failure The optimizations in d0645d1792e1cbdf417a923ea071975e4390fccd did not take into account 0-length reads, used in network programming to check connected state. By not returning early in the case where lastReadChunkSize == maxSize and maxSize == 0, we allow the underlying device to report error conditions on 0-length reads. This reverts commit aea71e2e02fa966842b094244bc3f5fc88f50f41, while still ensuring that QIODevice::read() returns -1 on a closed device. Reviewed-by: mread Reviewed-by: Thiago Macieira --- src/corelib/io/qiodevice.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index f2cef4e1..bb11d6b 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -755,7 +755,6 @@ qint64 QIODevice::bytesToWrite() const qint64 QIODevice::read(char *data, qint64 maxSize) { Q_D(QIODevice); - CHECK_READABLE(read, qint64(-1)); #if defined QIODEVICE_DEBUG printf("%p QIODevice::read(%p, %d), d->pos = %d, d->buffer.size() = %d\n", @@ -786,13 +785,13 @@ qint64 QIODevice::read(char *data, qint64 maxSize) do { // Try reading from the buffer. int lastReadChunkSize = d->buffer.read(data, maxSize); - *d->pPos += lastReadChunkSize; - readSoFar += lastReadChunkSize; - // fast exit when satisfied by buffer - if (lastReadChunkSize == maxSize && !(d->openMode & Text)) - return readSoFar; - if (lastReadChunkSize > 0) { + *d->pPos += lastReadChunkSize; + readSoFar += lastReadChunkSize; + // fast exit when satisfied by buffer + if (lastReadChunkSize == maxSize && !(d->openMode & Text)) + return readSoFar; + data += lastReadChunkSize; maxSize -= lastReadChunkSize; #if defined QIODEVICE_DEBUG -- cgit v0.12