Ignore:
Timestamp:
Mar 8, 2010, 12:52:58 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.2 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/network/access/qhttpnetworkconnectionchannel.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    167167#endif
    168168        socket->write(header);
     169
     170
    169171        QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
    170172        if (uploadByteDevice) {
     
    259261        // this is needed if the sends an reply before we have finished sending the request. In that
    260262        // case receiveReply had been called before but ignored the server reply
    261         receiveReply();
     263        );
    262264        break;
    263265    }
     
    273275
    274276
    275 void QHttpNetworkConnectionChannel::receiveReply()
     277void QHttpNetworkConnectionChannel::receiveReply()
    276278{
    277279    Q_ASSERT(socket);
     
    325327            break;
    326328        }
    327         case QHttpNetworkReplyPrivate::ReadingHeaderState:
    328             bytes += reply->d_func()->readHeader(socket);
    329             if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) {
    330                 if (reply->d_func()->isGzipped() && reply->d_func()->autoDecompress) {
     329        case QHttpNetworkReplyPrivate::ReadingHeaderState: {
     330            QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
     331            bytes += replyPrivate->readHeader(socket);
     332            if (replyPrivate->state == QHttpNetworkReplyPrivate::ReadingDataState) {
     333                if (replyPrivate->isGzipped() && replyPrivate->autoDecompress) {
    331334                    // remove the Content-Length from header
    332                     reply->d_func()->removeAutoDecompressHeader();
     335                    reply->removeAutoDecompressHeader();
    333336                } else {
    334                     reply->d_func()->autoDecompress = false;
     337                    reply->autoDecompress = false;
    335338                }
    336                 if (reply && reply->d_func()->statusCode == 100) {
    337                     reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState;
     339                if (reply->statusCode == 100) {
     340                    reply->state = QHttpNetworkReplyPrivate::ReadingStatusState;
    338341                    break; // ignore
    339342                }
    340                 if (reply->d_func()->shouldEmitSignals())
     343                if (reply->shouldEmitSignals())
    341344                    emit reply->headerChanged();
    342                 if (!reply->d_func()->expectContent()) {
    343                     reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState;
     345                if (!reply->expectContent()) {
     346                    reply->state = QHttpNetworkReplyPrivate::AllDoneState;
    344347                    this->state = QHttpNetworkConnectionChannel::IdleState;
    345348                    allDone();
     
    348351            }
    349352            break;
     353
    350354        case QHttpNetworkReplyPrivate::ReadingDataState: {
    351             if (!reply->d_func()->isChunked() && !reply->d_func()->autoDecompress
    352                 && reply->d_func()->bodyLength > 0) {
     355           QHttpNetworkReplyPrivate *replyPrivate = reply->d_func();
     356           if (replyPrivate->downstreamLimited && !replyPrivate->responseData.isEmpty() && replyPrivate->shouldEmitSignals()) {
     357               // We already have some HTTP body data. We don't read more from the socket until
     358               // this is fetched by QHttpNetworkAccessHttpBackend. If we would read more,
     359               // we could not limit our read buffer usage.
     360               // We only do this when shouldEmitSignals==true because our HTTP parsing
     361               // always needs to parse the 401/407 replies. Therefore they don't really obey
     362               // to the read buffer maximum size, but we don't care since they should be small.
     363               return;
     364           }
     365
     366            if (!replyPrivate->isChunked() && !replyPrivate->autoDecompress
     367                && replyPrivate->bodyLength > 0) {
    353368                // bulk files like images should fulfill these properties and
    354369                // we can therefore save on memory copying
    355                 bytes = reply->d_func()->readBodyFast(socket, &reply->d_func()->responseData);
    356                 reply->d_func()->totalProgress += bytes;
    357                 if (reply->d_func()->shouldEmitSignals()) {
     370                bytes = reply->responseData);
     371                reply->totalProgress += bytes;
     372                if (reply->shouldEmitSignals()) {
    358373                    QPointer<QHttpNetworkReply> replyPointer = reply;
    359374                    emit reply->readyRead();
     
    361376                    if (replyPointer.isNull())
    362377                        return;
    363                     emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength);
     378                    emit reply->dataReadProgress(reply->bodyLength);
    364379                    // make sure that the reply is valid
    365380                    if (replyPointer.isNull())
     
    372387                // no content-length etc)
    373388                QByteDataBuffer byteDatas;
    374                 bytes = reply->d_func()->readBody(socket, &byteDatas);
     389                bytes = reply->readBody(socket, &byteDatas);
    375390                if (bytes) {
    376                     if (reply->d_func()->autoDecompress)
    377                         reply->d_func()->appendCompressedReplyData(byteDatas);
     391                    if (reply->autoDecompress)
     392                        reply->appendCompressedReplyData(byteDatas);
    378393                    else
    379                         reply->d_func()->appendUncompressedReplyData(byteDatas);
    380 
    381                     if (!reply->d_func()->autoDecompress) {
    382                         reply->d_func()->totalProgress += bytes;
    383                         if (reply->d_func()->shouldEmitSignals()) {
     394                        reply->appendUncompressedReplyData(byteDatas);
     395
     396                    if (!reply->autoDecompress) {
     397                        reply->totalProgress += bytes;
     398                        if (reply->shouldEmitSignals()) {
    384399                            QPointer<QHttpNetworkReply> replyPointer = reply;
    385400                            // important: At the point of this readyRead(), the byteDatas list must be empty,
     
    389404                            if (replyPointer.isNull())
    390405                                return;
    391                             emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength);
     406                            emit reply->dataReadProgress(reply->bodyLength);
    392407                            // make sure that the reply is valid
    393408                           if (replyPointer.isNull())
     
    402417                }
    403418            }
    404             if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState)
     419            if (reply->state == QHttpNetworkReplyPrivate::ReadingDataState)
    405420                break;
    406421            // everything done, fall through
     
    418433bool QHttpNetworkConnectionChannel::ensureConnection()
    419434{
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
    420449    // make sure that this socket is in a connected state, if not initiate
    421450    // connection to the host.
    422     if (socket->state() != QAbstractSocket::ConnectedState) {
     451    if (socket != QAbstractSocket::ConnectedState) {
    423452        // connect to the host if not already connected.
    424         // resend this request after we receive the disconnected signal
    425         if (socket->state() == QAbstractSocket::ClosingState) {
    426             resendCurrent = true;
    427             return false;
    428         }
    429453        state = QHttpNetworkConnectionChannel::ConnectingState;
    430454        pendingEncrypt = connection->d_func()->encrypt;
     
    568592
    569593            // continue reading
    570             receiveReply();
     594            receiveReply();
    571595        }
    572596    } else if (alreadyPipelinedRequests.isEmpty() && socket->bytesAvailable() > 0) {
     
    617641{
    618642    char c;
    619     while (socket->bytesAvailable()) {
    620         if (socket->peek(&c, 1) != 1)
     643    do {
     644        qint64 ret = socket->peek(&c, 1);
     645
     646        // nothing read, fine.
     647        if (ret == 0)
    621648            return;
     649
     650
     651
     652
    622653
    623654        // read all whitespace and line endings
     
    628659            break;
    629660        }
    630     }
     661    }
    631662}
    632663
     
    740771        state = QHttpNetworkConnectionChannel::ReadingState;
    741772        if (reply)
    742             receiveReply();
     773            receiveReply();
    743774    }
    744775}
     
    759790        state = QHttpNetworkConnectionChannel::ReadingState;
    760791        if (reply)
    761             receiveReply();
     792            receiveReply();
    762793    } else if (state == QHttpNetworkConnectionChannel::IdleState && resendCurrent) {
    763794        // re-sending request because the socket was in ClosingState
     
    842873    }
    843874    QPointer<QObject> that = connection;
    844     QString errorString = connection->d_func()->errorDetail(errorCode, socket);
     875    QString errorString = connection->d_func()->errorDetail(errorCode, socket);
    845876    if (send2Reply) {
    846877        if (reply) {
Note: See TracChangeset for help on using the changeset viewer.