Details
-
Bug
-
Resolution: Done
-
P2: Important
-
None
-
4.8.4
-
None
-
Linux, opensuse 12.1.
Description
I'm trying to reuse a QTcpSocket instance. This is not actually my code but rather QtWebApp HTTP Server (http://stefanfrings.de/qtwebapp/index-en.html).
The problem is:
1) During the last connection, a lot of data was written to TcpSocket.
2) Connection was terminated by the remote side. Pending write data remains in QAbstractSocket.cpp::writeBuffer().
3) I tried calling disconnectFromHost() or abort() but since state is already UnconnectedState those functions don't actually execute the "d->writeBuffer.clear();" as expected.
3) A new connection arrives. QtWebApp reuses the disconnected socket by calling setSocketDescriptor()
4) setSocketDescriptor() uses the internal resetSocketLayer() function. So, supposedly, it was meant to work since the comment of this function says "Resets the socket layer, clears the read and write buffers and deletes any socket notifiers." However the function DOES NOT clear those buffers.
Please also notice that current comment of abort() is also misleading: "discarding any pending data in the write buffer." However this is also not true when (d->state == UnconnectedState) as it returns immediately.
So the effect is that remaining data from previous connection is copied over the new connection.
The only workaround I could think of was this:
socket.connectToHost("",0);
The connectToHost does clear the writebuffer as a side-effect, so this is obviously a very ugly workaround. I believe proper fix is resetSocketLayer() to do the writeBuffer.clear().
Attachments
For Gerrit Dashboard: QTBUG-28914 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
73476,3 | Clear read- and write buffers | stable | qt/qtbase | Status: MERGED | +2 | 0 |