diff options
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 37 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 31 |
3 files changed, 52 insertions, 18 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index abaa7fb..b40b4c8 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE -const int QHttpNetworkConnectionPrivate::channelCount = 2; +const int QHttpNetworkConnectionPrivate::channelCount = 6; QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt) : hostName(hostName), port(port), encrypt(encrypt), @@ -74,6 +74,7 @@ QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &host #endif { + channels = new Channel[channelCount]; } QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate() @@ -82,6 +83,7 @@ QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate() channels[i].socket->close(); delete channels[i].socket; } + delete []channels; } void QHttpNetworkConnectionPrivate::connectSignals(QAbstractSocket *socket) @@ -1090,25 +1092,26 @@ void QHttpNetworkConnectionPrivate::_q_disconnected() void QHttpNetworkConnectionPrivate::_q_startNextRequest() { - // send the current request again - if (channels[0].resendCurrent || channels[1].resendCurrent) { - int i = channels[0].resendCurrent ? 0:1; - QAbstractSocket *socket = channels[i].socket; - channels[i].resendCurrent = false; - channels[i].state = IdleState; - if (channels[i].reply) - sendRequest(socket); - return; + //resend the necessary ones. + for (int i = 0; i < channelCount; ++i) { + if (channels[i].resendCurrent) { + channels[i].resendCurrent = false; + channels[i].state = IdleState; + if (channels[i].reply) + sendRequest(channels[i].socket); + } } - // send the request using the idle socket - QAbstractSocket *socket = channels[0].socket; - if (isSocketBusy(socket)) { - socket = (isSocketBusy(channels[1].socket) ? 0 :channels[1].socket); + QAbstractSocket *socket = 0; + for (int i = 0; i < channelCount; ++i) { + QAbstractSocket *chSocket = channels[i].socket; + // send the request using the idle socket + if (!isSocketBusy(chSocket)) { + socket = chSocket; + break; + } } - - if (!socket) { + if (!socket) return; // this will be called after finishing current request. - } unqueueAndSendRequest(socket); } diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 4603a55..b5f3593 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -250,7 +250,7 @@ public: {} }; static const int channelCount; - Channel channels[2]; // maximum of 2 socket connections to the server + Channel *channels; // parallel connections to the server bool pendingAuthSignal; // there is an incomplete authentication signal bool pendingProxyAuthSignal; // there is an incomplete proxy authentication signal diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 43b4ea9..a93d0b6 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -243,6 +243,8 @@ private Q_SLOTS: void proxyChange(); void authorizationError_data(); void authorizationError(); + + void httpConnectionCount(); }; QT_BEGIN_NAMESPACE @@ -3665,5 +3667,34 @@ void tst_QNetworkReply::authorizationError() QCOMPARE(QString(reply->readAll()), httpBody); } +void tst_QNetworkReply::httpConnectionCount() +{ + QTcpServer server; + QVERIFY(server.listen()); + QCoreApplication::instance()->processEvents(); + + for (int i = 0; i < 10; i++) { + QNetworkRequest request (QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/" + QString::number(i))); + QNetworkReply* reply = manager.get(request); + reply->setParent(this); + } + + int pendingConnectionCount = 0; + QTime time; + time.start(); + + while(pendingConnectionCount != 6) { + QCoreApplication::instance()->processEvents(); + while (server.nextPendingConnection()) + pendingConnectionCount++; + + // at max. wait 10 sec + if (time.elapsed() > 10000) + break; + } + + QCOMPARE(pendingConnectionCount, 6); +} + QTEST_MAIN(tst_QNetworkReply) #include "tst_qnetworkreply.moc" |