753 \sa readData() readLine() write() |
753 \sa readData() readLine() write() |
754 */ |
754 */ |
755 qint64 QIODevice::read(char *data, qint64 maxSize) |
755 qint64 QIODevice::read(char *data, qint64 maxSize) |
756 { |
756 { |
757 Q_D(QIODevice); |
757 Q_D(QIODevice); |
758 CHECK_READABLE(read, qint64(-1)); |
|
759 |
758 |
760 #if defined QIODEVICE_DEBUG |
759 #if defined QIODEVICE_DEBUG |
761 printf("%p QIODevice::read(%p, %d), d->pos = %d, d->buffer.size() = %d\n", |
760 printf("%p QIODevice::read(%p, %d), d->pos = %d, d->buffer.size() = %d\n", |
762 this, data, int(maxSize), int(d->pos), int(d->buffer.size())); |
761 this, data, int(maxSize), int(d->pos), int(d->buffer.size())); |
763 #endif |
762 #endif |
784 qint64 readSoFar = 0; |
783 qint64 readSoFar = 0; |
785 bool moreToRead = true; |
784 bool moreToRead = true; |
786 do { |
785 do { |
787 // Try reading from the buffer. |
786 // Try reading from the buffer. |
788 int lastReadChunkSize = d->buffer.read(data, maxSize); |
787 int lastReadChunkSize = d->buffer.read(data, maxSize); |
789 *d->pPos += lastReadChunkSize; |
|
790 readSoFar += lastReadChunkSize; |
|
791 // fast exit when satisfied by buffer |
|
792 if (lastReadChunkSize == maxSize && !(d->openMode & Text)) |
|
793 return readSoFar; |
|
794 |
|
795 if (lastReadChunkSize > 0) { |
788 if (lastReadChunkSize > 0) { |
|
789 *d->pPos += lastReadChunkSize; |
|
790 readSoFar += lastReadChunkSize; |
|
791 // fast exit when satisfied by buffer |
|
792 if (lastReadChunkSize == maxSize && !(d->openMode & Text)) |
|
793 return readSoFar; |
|
794 |
796 data += lastReadChunkSize; |
795 data += lastReadChunkSize; |
797 maxSize -= lastReadChunkSize; |
796 maxSize -= lastReadChunkSize; |
798 #if defined QIODEVICE_DEBUG |
797 #if defined QIODEVICE_DEBUG |
799 printf("%p \treading %d bytes from buffer into position %d\n", this, lastReadChunkSize, |
798 printf("%p \treading %d bytes from buffer into position %d\n", this, lastReadChunkSize, |
800 int(readSoFar) - lastReadChunkSize); |
799 int(readSoFar) - lastReadChunkSize); |