summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qiodevice.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao@trolltech.com>2010-04-15 17:02:34 (GMT)
committerJoão Abecasis <joao@trolltech.com>2010-04-19 11:48:06 (GMT)
commit02532ec80375c686503c4250c6ad6bb211515ec8 (patch)
treeea1907646aa373aad0b30dfef4bcde84f9775c7b /src/corelib/io/qiodevice.cpp
parented91e29b23a07879a748c199902e3bf3fe6cd73f (diff)
downloadQt-02532ec80375c686503c4250c6ad6bb211515ec8.zip
Qt-02532ec80375c686503c4250c6ad6bb211515ec8.tar.gz
Qt-02532ec80375c686503c4250c6ad6bb211515ec8.tar.bz2
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
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r--src/corelib/io/qiodevice.cpp13
1 files 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