summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2018-01-18 15:08:13 +0100
committerJesus Fernandez <Jesus.Fernandez@qt.io>2018-01-18 16:51:58 +0000
commita3495e515da0ffee896888cfa0f2d364b129ed2c (patch)
treebe23fba3e02967b999e5c4b239aed55a7cc696cd
parent272eaa037f3f8644a07f28c404d23c97bc88b560 (diff)
Fix reading body incomplete body
Sometimes the body was not available when reading. Change-Id: I2eab85b94b416ba1ed05a78732458b7eb5a5eb51 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--tests/auto/shared/webserver.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/auto/shared/webserver.h b/tests/auto/shared/webserver.h
index 458c24a..b28a0e5 100644
--- a/tests/auto/shared/webserver.h
+++ b/tests/auto/shared/webserver.h
@@ -32,6 +32,7 @@
#include <functional>
#include <cctype>
+#include <QtCore/qcoreapplication.h>
#include <QtNetwork/qtcpserver.h>
class WebServer : public QTcpServer
@@ -268,8 +269,14 @@ bool WebServer::HttpRequest::readBody(QTcpSocket *socket)
return false;
fragment.resize(bytesLeft);
}
- while (socket->bytesAvailable() && bytesLeft)
- bytesLeft -= socket->read(&fragment.data()[fragment.size() - bytesLeft], bytesLeft);
+ while (bytesLeft) {
+ int got = socket->read(&fragment.data()[fragment.size() - bytesLeft], bytesLeft);
+ if (got < 0)
+ return false; // error
+ bytesLeft -= got;
+ if (bytesLeft)
+ qApp->processEvents();
+ }
fragment.swap(body);
state = State::AllDone;
return true;