src/network/access/qhttpnetworkconnection.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
child 5 d3bac044e0f0
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtNetwork module of the Qt Toolkit.
     7 ** This file is part of the QtNetwork module of the Qt Toolkit.
     8 **
     8 **
   413     case QHttpNetworkRequest::NormalPriority:
   413     case QHttpNetworkRequest::NormalPriority:
   414     case QHttpNetworkRequest::LowPriority:
   414     case QHttpNetworkRequest::LowPriority:
   415         lowPriorityQueue.prepend(pair);
   415         lowPriorityQueue.prepend(pair);
   416         break;
   416         break;
   417     }
   417     }
   418     QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
   418     // this used to be called via invokeMethod and a QueuedConnection
       
   419     _q_startNextRequest();
   419     return reply;
   420     return reply;
   420 }
   421 }
   421 
   422 
   422 void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair)
   423 void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair)
   423 {
   424 {
   424     Q_Q(QHttpNetworkConnection);
       
   425 
       
   426     QHttpNetworkRequest request = pair.first;
   425     QHttpNetworkRequest request = pair.first;
   427     switch (request.priority()) {
   426     switch (request.priority()) {
   428     case QHttpNetworkRequest::HighPriority:
   427     case QHttpNetworkRequest::HighPriority:
   429         highPriorityQueue.prepend(pair);
   428         highPriorityQueue.prepend(pair);
   430         break;
   429         break;
   431     case QHttpNetworkRequest::NormalPriority:
   430     case QHttpNetworkRequest::NormalPriority:
   432     case QHttpNetworkRequest::LowPriority:
   431     case QHttpNetworkRequest::LowPriority:
   433         lowPriorityQueue.prepend(pair);
   432         lowPriorityQueue.prepend(pair);
   434         break;
   433         break;
   435     }
   434     }
   436     QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
   435     // this used to be called via invokeMethod and a QueuedConnection
       
   436     _q_startNextRequest();
   437 }
   437 }
   438 
   438 
   439 void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socket)
   439 void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socket)
   440 {
   440 {
   441     Q_ASSERT(socket);
   441     Q_ASSERT(socket);
   689             channels[i].state = QHttpNetworkConnectionChannel::IdleState;
   689             channels[i].state = QHttpNetworkConnectionChannel::IdleState;
   690             if (channels[i].reply)
   690             if (channels[i].reply)
   691                 channels[i].sendRequest();
   691                 channels[i].sendRequest();
   692         }
   692         }
   693     }
   693     }
       
   694 
       
   695     // dequeue new ones
       
   696 
   694     QAbstractSocket *socket = 0;
   697     QAbstractSocket *socket = 0;
   695     for (int i = 0; i < channelCount; ++i) {
   698     for (int i = 0; i < channelCount; ++i) {
   696         QAbstractSocket *chSocket = channels[i].socket;
   699         QAbstractSocket *chSocket = channels[i].socket;
   697         // send the request using the idle socket
   700         // try to get a free AND connected socket
   698         if (!channels[i].isSocketBusy()) {
   701         if (!channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) {
   699             socket = chSocket;
   702             socket = chSocket;
       
   703             dequeueAndSendRequest(socket);
   700             break;
   704             break;
   701         }
   705         }
   702     }
   706     }
   703 
   707 
   704     // this socket is free,
   708     if (!socket) {
   705     if (socket)
   709         for (int i = 0; i < channelCount; ++i) {
   706         dequeueAndSendRequest(socket);
   710             QAbstractSocket *chSocket = channels[i].socket;
       
   711             // try to get a free unconnected socket
       
   712             if (!channels[i].isSocketBusy()) {
       
   713                 socket = chSocket;
       
   714                 dequeueAndSendRequest(socket);
       
   715                 break;
       
   716             }
       
   717         }
       
   718     }
   707 
   719 
   708     // try to push more into all sockets
   720     // try to push more into all sockets
   709     // ### FIXME we should move this to the beginning of the function
   721     // ### FIXME we should move this to the beginning of the function
   710     // as soon as QtWebkit is properly using the pipelining
   722     // as soon as QtWebkit is properly using the pipelining
   711     // (e.g. not for XMLHttpRequest or the first page load)
   723     // (e.g. not for XMLHttpRequest or the first page load)
   729                 channels[i].sendRequest();
   741                 channels[i].sendRequest();
   730         }
   742         }
   731     }
   743     }
   732 }
   744 }
   733 
   745 
       
   746 void QHttpNetworkConnectionPrivate::readMoreLater(QHttpNetworkReply *reply)
       
   747 {
       
   748     for (int i = 0 ; i < channelCount; ++i) {
       
   749         if (channels[i].reply ==  reply) {
       
   750             // emulate a readyRead() from the socket
       
   751             QMetaObject::invokeMethod(&channels[i], "_q_readyRead", Qt::QueuedConnection);
       
   752             return;
       
   753         }
       
   754     }
       
   755 }
   734 
   756 
   735 QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, QObject *parent)
   757 QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, QObject *parent)
   736     : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt)), parent)
   758     : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt)), parent)
   737 {
   759 {
   738     Q_D(QHttpNetworkConnection);
   760     Q_D(QHttpNetworkConnection);