QNAM: Fix upload corruptions when server closes connection
authorMarkus Goetz <markus@woboq.com>
Tue, 28 Apr 2015 09:57:36 +0000 (11:57 +0200)
committerDaniel Molkentin (ownCloud) <danimo@owncloud.com>
Tue, 28 Apr 2015 18:01:16 +0000 (18:01 +0000)
commitfa81aa6d027049e855b76f5408586a288f160575
tree72007f902f5db5ee78703d3beedff0534260f31f
parentec701869f5c7f70608e71331223b22454c3a3e4c
QNAM: Fix upload corruptions when server closes connection

This patch fixes several upload corruptions if the server closes the connection
while/before we send data into it. They happen inside multiple places in the HTTP
layer and are explained in the comments.
Corruptions are:
* The upload byte device has an in-flight signal with pending upload data, if
it gets reset (because server closes the connection) then the re-send of the
request was sometimes taking this stale in-flight pending upload data.
* Because some signals were DirectConnection and some were QueuedConnection, there
was a chance that a direct signal overtakes a queued signal. The state machine
then sent data down the socket which was buffered there (and sent later) although
it did not match the current state of the state machine when it was actually sent.
* A socket was seen as being able to have requests sent even though it was not
encrypted yet. This relates to the previous corruption where data is stored inside
the socket's buffer and then sent later.

The included auto test produces all fixed corruptions, I detected no regressions
via the other tests.
This code also adds a bit of sanity checking to protect from possible further
problems.

[ChangeLog][QtNetwork] Fix HTTP(s) upload corruption when server closes connection

(cherry picked from commit qtbase/cff39fba10ffc10ee4dcfdc66ff6528eb26462d3)
Change-Id: I9793297be6cf3edfb75b65ba03b65f7a133ef194
Reviewed-by: Richard J. Moore <rich@kde.org>
src/corelib/io/qnoncontiguousbytedevice.cpp
src/corelib/io/qnoncontiguousbytedevice_p.h
src/network/access/qhttpnetworkconnectionchannel.cpp
src/network/access/qhttpthreaddelegate_p.h
src/network/access/qnetworkaccesshttpbackend.cpp
src/network/access/qnetworkaccesshttpbackend_p.h
tests/auto/qnetworkreply/tst_qnetworkreply.cpp