src/network/access/qhttpnetworkconnection.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 5 d3bac044e0f0
--- a/src/network/access/qhttpnetworkconnection.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/network/access/qhttpnetworkconnection.cpp	Fri Feb 19 23:40:16 2010 +0200
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -415,14 +415,13 @@
         lowPriorityQueue.prepend(pair);
         break;
     }
-    QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
+    // this used to be called via invokeMethod and a QueuedConnection
+    _q_startNextRequest();
     return reply;
 }
 
 void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair)
 {
-    Q_Q(QHttpNetworkConnection);
-
     QHttpNetworkRequest request = pair.first;
     switch (request.priority()) {
     case QHttpNetworkRequest::HighPriority:
@@ -433,7 +432,8 @@
         lowPriorityQueue.prepend(pair);
         break;
     }
-    QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
+    // this used to be called via invokeMethod and a QueuedConnection
+    _q_startNextRequest();
 }
 
 void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socket)
@@ -691,19 +691,31 @@
                 channels[i].sendRequest();
         }
     }
+
+    // dequeue new ones
+
     QAbstractSocket *socket = 0;
     for (int i = 0; i < channelCount; ++i) {
         QAbstractSocket *chSocket = channels[i].socket;
-        // send the request using the idle socket
-        if (!channels[i].isSocketBusy()) {
+        // try to get a free AND connected socket
+        if (!channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) {
             socket = chSocket;
+            dequeueAndSendRequest(socket);
             break;
         }
     }
 
-    // this socket is free,
-    if (socket)
-        dequeueAndSendRequest(socket);
+    if (!socket) {
+        for (int i = 0; i < channelCount; ++i) {
+            QAbstractSocket *chSocket = channels[i].socket;
+            // try to get a free unconnected socket
+            if (!channels[i].isSocketBusy()) {
+                socket = chSocket;
+                dequeueAndSendRequest(socket);
+                break;
+            }
+        }
+    }
 
     // try to push more into all sockets
     // ### FIXME we should move this to the beginning of the function
@@ -731,6 +743,16 @@
     }
 }
 
+void QHttpNetworkConnectionPrivate::readMoreLater(QHttpNetworkReply *reply)
+{
+    for (int i = 0 ; i < channelCount; ++i) {
+        if (channels[i].reply ==  reply) {
+            // emulate a readyRead() from the socket
+            QMetaObject::invokeMethod(&channels[i], "_q_readyRead", Qt::QueuedConnection);
+            return;
+        }
+    }
+}
 
 QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, QObject *parent)
     : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt)), parent)