diff options
author | Martin Petersson <martin.petersson@nokia.com> | 2011-03-10 12:31:36 (GMT) |
---|---|---|
committer | Martin Petersson <martin.petersson@nokia.com> | 2011-03-10 12:36:28 (GMT) |
commit | 096eed1745d78ae8377f0231871100fd5ba6a78e (patch) | |
tree | f84bc5046493719ffa25b17925116732c1f79120 /src/network/access/qhttpnetworkconnection.cpp | |
parent | 3e2db2ed3c8f12534871cc1fb014210b471d55cf (diff) | |
download | Qt-096eed1745d78ae8377f0231871100fd5ba6a78e.zip Qt-096eed1745d78ae8377f0231871100fd5ba6a78e.tar.gz Qt-096eed1745d78ae8377f0231871100fd5ba6a78e.tar.bz2 |
QNAM HTTP: Pair channels with requests at a later state.
Connect a new channel only when there is no one currently available.
Only pair the request with the channel once we know if it got connected
or not. This leads to faster sending on requests as we reuse already
connected channels that became free in the meanwhile.
Task-number: QTBUG-17084
Reviewed-by: Markus Goetz
Reviewed-by: Peter Hartmann
Diffstat (limited to 'src/network/access/qhttpnetworkconnection.cpp')
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 35c3a67..29ae5b0 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -487,7 +487,7 @@ void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair) QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); } -void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socket) +bool QHttpNetworkConnectionPrivate::dequeueRequest(QAbstractSocket *socket) { Q_ASSERT(socket); @@ -500,8 +500,7 @@ void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socke prepareRequest(messagePair); channels[i].request = messagePair.first; channels[i].reply = messagePair.second; - channels[i].sendRequest(); - return; + return true; } if (!lowPriorityQueue.isEmpty()) { @@ -511,9 +510,9 @@ void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socke prepareRequest(messagePair); channels[i].request = messagePair.first; channels[i].reply = messagePair.second; - channels[i].sendRequest(); - return; + return true; } + return false; } // this is called from _q_startNextRequest and when a request has been sent down a socket from the channel @@ -784,17 +783,8 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() // try to get a free AND connected socket for (int i = 0; i < channelCount; ++i) { if (!channels[i].reply && !channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) { - dequeueAndSendRequest(channels[i].socket); - } - } - - // return fast if there is nothing to do - if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty()) - return; - // try to get a free unconnected socket - for (int i = 0; i < channelCount; ++i) { - if (!channels[i].reply && !channels[i].isSocketBusy()) { - dequeueAndSendRequest(channels[i].socket); + if (dequeueRequest(channels[i].socket)) + channels[i].sendRequest(); } } @@ -811,6 +801,21 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() for (int i = 0; i < channelCount; i++) if (channels[i].socket->state() == QAbstractSocket::ConnectedState) fillPipeline(channels[i].socket); + + // If there is not already any connected channels we need to connect a new one. + // We do not pair the channel with the request until we know if it is + // connected or not. This is to reuse connected channels before we connect new once. + int queuedRequest = highPriorityQueue.count() + lowPriorityQueue.count(); + for (int i = 0; i < channelCount; ++i) { + if (channels[i].socket->state() == QAbstractSocket::ConnectingState) + queuedRequest--; + if ( queuedRequest <=0 ) + break; + if (!channels[i].reply && !channels[i].isSocketBusy() && (channels[i].socket->state() == QAbstractSocket::UnconnectedState)) { + channels[i].ensureConnection(); + queuedRequest--; + } + } } |