Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.4.0
-
None
-
7d257aab8175f3d4fd3b838d4f47457a8d868885,184d66caa5f7f93b7383319c5c8985524e0dc824
Description
If QDataStream encounters a ReadPastEnd it should reset the device to the last known state, putting back any characters that have not successfully been parsed yet.
Use Case
It should be straightforward to use a QDataStream e.g. for communication over a socket. However, all relevant network protocols are packet based, and it's not guaranteed that the chunks of data arriving with readyRead can be de-serialized completely.
If one tries to process an incomplete chunk QDataStream will flag this with ReadPastEnd. However, it won't put any characters back to the device, meaning that the user cannot reasonably recover, and wait for more data to arrive.
Alternatives
The fortuneclient example works around this by wrapping the streamed data again in a QByteArray, and prepending it with it's own size. However, this relies on the implementation detail that streaming a qint16 will write exactly 2 bytes on the device.
Proposed fix
All QDataStream::operator<<() should use e.g. ungetChar to restore the QIODevice data into a consistent state. This way, the user can easily just 'bail out' in case of an uncomplete read, and wait for more data to arrive to continue reading.
Attachments
Issue Links
- relates to
-
QTBUG-56032 [REG 5.6->5.7] Performance drop for QIODevice::peek
- Closed
- resulted in
-
QTBUG-118202 QDataStream/QIODevice transactions
- Open
For Gerrit Dashboard: QTBUG-44418 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
107985,33 | QDataStream: handle incomplete reads from QIODevice | dev | qt/qtbase | Status: MERGED | +2 | 0 |
114792,26 | QIODevice: handle incomplete reads | dev | qt/qtbase | Status: MERGED | +2 | 0 |