From 48345e5d3c07d6dca12dd4ccee18fa3e0ca0ebda Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Tue, 11 Jun 2013 10:45:41 +0200 Subject: HTTP internals: do not open too many sockets when preconnecting Each pair of (normal request, preconnect request) requires only one socket. E.g. if there is 1 preconnect request in-flight and 2 normal requests, we need only 2 sockets in total, and not 3. Therefore, we need to keep track of whether a request is preconnecting or a normal one. Task-number: QTBUG-31594 Change-Id: If92ccc35abadfa6090d64ee92bd466615909c94c Reviewed-by: Richard J. Moore --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp index 860bd3cf4d..a99fd17a64 100644 --- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -463,6 +463,7 @@ private slots: #ifndef QT_NO_SSL void echoPerformance_data(); void echoPerformance(); + void preConnectEncrypted_data(); void preConnectEncrypted(); #endif @@ -476,6 +477,7 @@ private slots: void httpDownloadPerformanceDownloadBuffer(); void httpsRequestChain(); void httpsUpload(); + void preConnect_data(); void preConnect(); private: @@ -548,6 +550,13 @@ void tst_qnetworkreply::echoPerformance() } } +void tst_qnetworkreply::preConnectEncrypted_data() +{ + QTest::addColumn("sleepTime"); + QTest::newRow("2secs") << 2000; // to start a new request after preconnecting is done + QTest::newRow("100ms") << 100; // to start a new request while preconnecting is in-flight +} + void tst_qnetworkreply::preConnectEncrypted() { QString hostName = QLatin1String("www.google.com"); @@ -579,8 +588,9 @@ void tst_qnetworkreply::preConnectEncrypted() manager.clearAccessCache(); // now try to make the connection beforehand + QFETCH(int, sleepTime); manager.connectToHostEncrypted(hostName); - QTestEventLoop::instance().enterLoop(2); + QTestEventLoop::instance().enterLoopMSecs(sleepTime); // now make another request and hopefully use the existing connection QPair preConnectResult = runGetRequest(&manager, request); @@ -917,6 +927,11 @@ void tst_qnetworkreply::httpsUpload() } } +void tst_qnetworkreply::preConnect_data() +{ + preConnectEncrypted_data(); +} + void tst_qnetworkreply::preConnect() { QString hostName = QLatin1String("www.google.com"); @@ -948,8 +963,9 @@ void tst_qnetworkreply::preConnect() manager.clearAccessCache(); // now try to make the connection beforehand + QFETCH(int, sleepTime); manager.connectToHost(hostName); - QTestEventLoop::instance().enterLoop(2); + QTestEventLoop::instance().enterLoopMSecs(sleepTime); // now make another request and hopefully use the existing connection QPair preConnectResult = runGetRequest(&manager, request); -- cgit v1.2.3