QHttpPrivate Class Reference

Inheritance diagram for QHttpPrivate:

Inheritance graph
[legend]
Collaboration diagram for QHttpPrivate:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 65 of file qhttp.cpp.

Public Member Functions

 QHttpPrivate ()
 ~QHttpPrivate ()
void _q_startNextRequest ()
void _q_slotReadyRead ()
void _q_slotConnected ()
void _q_slotError (QAbstractSocket::SocketError)
void _q_slotClosed ()
void _q_slotBytesWritten (qint64 numBytes)
void _q_slotDoFinished ()
void _q_slotSendRequest ()
int addRequest (QHttpRequest *)
void finishedWithSuccess ()
void finishedWithError (const QString &detail, int errorCode)
void init ()
void setState (int)
void closeConn ()
void setSock (QTcpSocket *sock)

Public Attributes

QTcpSocket * socket
int reconnectAttempts
bool deleteSocket
QList< QHttpRequest * > pending
QHttp::State state
QHttp::Error error
QString errorString
QString hostName
quint16 port
QByteArray buffer
QIODevice * toDevice
QIODevice * postDevice
qint64 bytesDone
qint64 bytesTotal
qint64 chunkedSize
QHttpRequestHeader header
bool readHeader
QString headerStr
QHttpResponseHeader response
QRingBuffer rba
QString userName
QString password
QString proxyHost
int proxyPort
QString proxyUser
QString proxyPassword


Constructor & Destructor Documentation

QHttpPrivate::QHttpPrivate (  )  [inline]

Definition at line 70 of file qhttp.cpp.

00070                           : socket(0), reconnectAttempts(2),
00071           deleteSocket(0), state(QHttp::Unconnected),
00072           error(QHttp::NoError), port(0), toDevice(0),
00073           postDevice(0), bytesDone(0), chunkedSize(-1)
00074     {
00075     }

QHttpPrivate::~QHttpPrivate (  )  [inline]

Definition at line 77 of file qhttp.cpp.

References deleteSocket, QList< T >::isEmpty(), pending, socket, and QList< T >::takeFirst().

00078     {
00079         while (!pending.isEmpty())
00080             delete pending.takeFirst();
00081 
00082         if (deleteSocket)
00083             delete socket;
00084     }

Here is the call graph for this function:


Member Function Documentation

void QHttpPrivate::_q_startNextRequest (  ) 

Definition at line 2215 of file qhttp.cpp.

References emit, error, errorString, QList< T >::first(), QHttpRequest::id, QList< T >::isEmpty(), QHttp::NoError, pending, and QHttpRequest::start().

Referenced by finishedWithSuccess().

02216 {
02217     Q_Q(QHttp);
02218     if (pending.isEmpty())
02219         return;
02220     QHttpRequest *r = pending.first();
02221 
02222     error = QHttp::NoError;
02223     errorString = QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown error"));
02224 
02225     if (q->bytesAvailable() != 0)
02226         q->readAll(); // clear the data
02227     emit q->requestStarted(r->id);
02228     r->start(q);
02229 }

Here is the call graph for this function:

void QHttpPrivate::_q_slotReadyRead (  ) 

Definition at line 2431 of file qhttp.cpp.

References buffer, QAbstractSocket::bytesAvailable(), bytesDone, QAbstractSocket::canReadLine(), chunkedSize, closeConn(), QHttp::Connected, QByteArray::constData(), QHttpHeader::contentLength(), QByteArray::data(), emit, finishedWithError(), QString::fromAscii(), QHttpHeader::hasContentLength(), headerStr, QString::indexOf(), QHttp::InvalidResponseHeader, QMetaObject::invokeMethod(), n, ptr, qDebug(), qMin(), Qt::QueuedConnection, rba, QIODevice::read(), QIODevice::readAll(), readHeader, QHttp::Reading, QIODevice::readLine(), QRingBuffer::reserve(), QByteArray::resize(), response, setState(), QByteArray::size(), socket, state, toDevice, QString::toInt(), QString::toLatin1(), QString::toLower(), QString::truncate(), QHttpHeader::value(), QIODevice::write(), and QHttp::WrongContentLength.

Referenced by setSock().

02432 {
02433     Q_Q(QHttp);
02434     if (state != QHttp::Reading) {
02435         setState(QHttp::Reading);
02436         buffer = QByteArray();
02437         readHeader = true;
02438         headerStr = QLatin1String("");
02439         bytesDone = 0;
02440         chunkedSize = -1;
02441     }
02442 
02443     while (readHeader) {
02444         bool end = false;
02445         QString tmp;
02446         while (!end && socket->canReadLine()) {
02447             tmp = QString::fromAscii(socket->readLine());
02448             if (tmp == QLatin1String("\r\n") || tmp == QLatin1String("\n"))
02449                 end = true;
02450             else
02451                 headerStr += tmp;
02452         }
02453 
02454         if (!end)
02455             return;
02456 
02457 #if defined(QHTTP_DEBUG)
02458         qDebug("QHttp: read response header:\n---{\n%s}---", headerStr.toLatin1().constData());
02459 #endif
02460         response = QHttpResponseHeader(headerStr);
02461         headerStr = QLatin1String("");
02462 #if defined(QHTTP_DEBUG)
02463         qDebug("QHttp: read response header:\n---{\n%s}---", response.toString().toLatin1().constData());
02464 #endif
02465         // Check header
02466         if (!response.isValid()) {
02467             finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP response header")),
02468                               QHttp::InvalidResponseHeader);
02469             closeConn();
02470             return;
02471         }
02472 
02473         // The 100-continue header is ignored, because when using the
02474         // POST method, we send both the request header and data in
02475         // one chunk.
02476         if (response.statusCode() != 100) {
02477             readHeader = false;
02478             if (response.hasKey(QLatin1String("transfer-encoding")) &&
02479                 response.value(QLatin1String("transfer-encoding")).toLower().contains(QLatin1String("chunked")))
02480                 chunkedSize = 0;
02481 
02482             emit q->responseHeaderReceived(response);
02483         }
02484     }
02485 
02486     if (!readHeader) {
02487         bool everythingRead = false;
02488 
02489         if (q->currentRequest().method() == QLatin1String("HEAD")) {
02490             everythingRead = true;
02491         } else {
02492             qint64 n = socket->bytesAvailable();
02493             QByteArray *arr = 0;
02494             if (chunkedSize != -1) {
02495                 // transfer-encoding is chunked
02496                 for (;;) {
02497                     // get chunk size
02498                     if (chunkedSize == 0) {
02499                         if (!socket->canReadLine())
02500                             break;
02501                         QString sizeString = QString::fromAscii(socket->readLine());
02502                         int tPos = sizeString.indexOf(QLatin1Char(';'));
02503                         if (tPos != -1)
02504                             sizeString.truncate(tPos);
02505                         bool ok;
02506                         chunkedSize = sizeString.toInt(&ok, 16);
02507                         if (!ok) {
02508                             finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP chunked body")),
02509                                               QHttp::WrongContentLength);
02510                             closeConn();
02511                             delete arr;
02512                             return;
02513                         }
02514                         if (chunkedSize == 0) // last-chunk
02515                             chunkedSize = -2;
02516                     }
02517 
02518                     // read trailer
02519                     while (chunkedSize == -2 && socket->canReadLine()) {
02520                         QString read = QString::fromAscii(socket->readLine());
02521                         if (read == QLatin1String("\r\n") || read == QLatin1String("\n"))
02522                             chunkedSize = -1;
02523                     }
02524                     if (chunkedSize == -1) {
02525                         everythingRead = true;
02526                         break;
02527                     }
02528 
02529                     // make sure that you can read the terminating CRLF,
02530                     // otherwise wait until next time...
02531                     n = socket->bytesAvailable();
02532                     if (n == 0)
02533                         break;
02534                     if (n == chunkedSize || n == chunkedSize+1) {
02535                         n = chunkedSize - 1;
02536                         if (n == 0)
02537                             break;
02538                     }
02539 
02540                     // read data
02541                     qint64 toRead = chunkedSize < 0 ? n : qMin(n, chunkedSize);
02542                     if (!arr)
02543                         arr = new QByteArray;
02544                     uint oldArrSize = arr->size();
02545                     arr->resize(oldArrSize + toRead);
02546                     qint64 read = socket->read(arr->data()+oldArrSize, toRead);
02547                     arr->resize(oldArrSize + read);
02548 
02549                     chunkedSize -= read;
02550 
02551                     if (chunkedSize == 0 && n - read >= 2) {
02552                         // read terminating CRLF
02553                         char tmp[2];
02554                         socket->read(tmp, 2);
02555                         if (tmp[0] != '\r' || tmp[1] != '\n') {
02556                             finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP chunked body")),
02557                                               QHttp::WrongContentLength);
02558                             closeConn();
02559                             delete arr;
02560                             return;
02561                         }
02562                     }
02563                 }
02564             } else if (response.hasContentLength()) {
02565                 n = qMin(qint64(response.contentLength() - bytesDone), n);
02566                 if (n > 0) {
02567                     arr = new QByteArray;
02568                     arr->resize(n);
02569                     qint64 read = socket->read(arr->data(), n);
02570                     arr->resize(read);
02571                 }
02572                 if (bytesDone + q->bytesAvailable() + n == response.contentLength())
02573                     everythingRead = true;
02574             } else if (n > 0) {
02575                 // workaround for VC++ bug
02576                 QByteArray temp = socket->readAll();
02577                 arr = new QByteArray(temp);
02578             }
02579 
02580             if (arr) {
02581                 n = arr->size();
02582                 if (toDevice) {
02583                     toDevice->write(*arr, n);
02584                     delete arr;
02585                     arr = 0;
02586                     bytesDone += n;
02587 #if defined(QHTTP_DEBUG)
02588                     qDebug("QHttp::_q_slotReadyRead(): read %lld bytes (%lld bytes done)", n, bytesDone);
02589 #endif
02590                     if (response.hasContentLength())
02591                         emit q->dataReadProgress(bytesDone, response.contentLength());
02592                     else
02593                         emit q->dataReadProgress(bytesDone, 0);
02594                 } else {
02595                     char *ptr = rba.reserve(arr->size());
02596                     memcpy(ptr, arr->data(), arr->size());
02597                     delete arr;
02598                     arr = 0;
02599 #if defined(QHTTP_DEBUG)
02600                     qDebug("QHttp::_q_slotReadyRead(): read %lld bytes (%lld bytes done)", n, bytesDone + q->bytesAvailable());
02601 #endif
02602                     if (response.hasContentLength())
02603                         emit q->dataReadProgress(bytesDone + q->bytesAvailable(), response.contentLength());
02604                     else
02605                         emit q->dataReadProgress(bytesDone + q->bytesAvailable(), 0);
02606                     emit q->readyRead(response);
02607                 }
02608             }
02609         }
02610 
02611         if (everythingRead) {
02612             // Handle "Connection: close"
02613             if (response.value(QLatin1String("connection")).toLower() == QLatin1String("close")) {
02614                 closeConn();
02615             } else {
02616                 setState(QHttp::Connected);
02617                 // Start a timer, so that we emit the keep alive signal
02618                 // "after" this method returned.
02619                 QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
02620             }
02621         }
02622     }
02623 }

Here is the call graph for this function:

void QHttpPrivate::_q_slotConnected (  ) 

Definition at line 2346 of file qhttp.cpp.

References buffer, bytesDone, bytesTotal, QByteArray::constData(), header, QString::length(), postDevice, qDebug(), QHttp::Sending, setState(), QIODevice::size(), QByteArray::size(), socket, state, QString::toLatin1(), QHttpRequestHeader::toString(), and QIODevice::write().

Referenced by _q_slotSendRequest(), and setSock().

02347 {
02348     if (state != QHttp::Sending) {
02349         bytesDone = 0;
02350         setState(QHttp::Sending);
02351     }
02352 
02353     QString str = header.toString();
02354     bytesTotal = str.length();
02355     socket->write(str.toLatin1(), bytesTotal);
02356 #if defined(QHTTP_DEBUG)
02357     qDebug("QHttp: write request header %p:\n---{\n%s}---", &header, str.toLatin1().constData());
02358 #endif
02359 
02360     if (postDevice) {
02361         bytesTotal += postDevice->size();
02362     } else {
02363         bytesTotal += buffer.size();
02364         socket->write(buffer, buffer.size());
02365         buffer = QByteArray(); // save memory
02366     }
02367 }

Here is the call graph for this function:

void QHttpPrivate::_q_slotError ( QAbstractSocket::SocketError   ) 

Definition at line 2369 of file qhttp.cpp.

References QAbstractSocket::abort(), QObject::blockSignals(), closeConn(), QHttp::Closing, QHttp::Connecting, QHttp::ConnectionRefused, QAbstractSocket::ConnectionRefusedError, finishedWithError(), QString::fromLatin1(), QHttp::HostNotFound, QAbstractSocket::HostNotFoundError, QMetaObject::invokeMethod(), QAbstractSocket::peerName(), postDevice, Qt::QueuedConnection, QHttp::Reading, reconnectAttempts, QAbstractSocket::RemoteHostClosedError, QHttp::Sending, setState(), socket, state, QHttp::Unconnected, and QHttp::UnknownError.

Referenced by setSock().

02370 {
02371     Q_Q(QHttp);
02372     postDevice = 0;
02373 
02374     if (state == QHttp::Connecting || state == QHttp::Reading || state == QHttp::Sending) {
02375         switch (err) {
02376         case QTcpSocket::ConnectionRefusedError:
02377             finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Connection refused")), QHttp::ConnectionRefused);
02378             break;
02379         case QTcpSocket::HostNotFoundError:
02380             finishedWithError(QString::fromLatin1(QT_TRANSLATE_NOOP("QHttp", "Host %1 not found"))
02381                               .arg(socket->peerName()), QHttp::HostNotFound);
02382             break;
02383         case QTcpSocket::RemoteHostClosedError:
02384             if (state == QHttp::Sending && reconnectAttempts--) {
02385                 setState(QHttp::Closing);
02386                 setState(QHttp::Unconnected);
02387                 socket->blockSignals(true);
02388                 socket->abort();
02389                 socket->blockSignals(false);
02390                 QMetaObject::invokeMethod(q, "_q_slotSendRequest", Qt::QueuedConnection);
02391                 return;
02392             }
02393             break;
02394         default:
02395             finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "HTTP request failed")), QHttp::UnknownError);
02396             break;
02397         }
02398     }
02399 
02400     closeConn();
02401 }

Here is the call graph for this function:

void QHttpPrivate::_q_slotClosed (  ) 

Definition at line 2324 of file qhttp.cpp.

References bytesDone, QHttp::Closing, QHttp::Connecting, QHttpHeader::contentLength(), finishedWithError(), QHttpHeader::hasKey(), QMetaObject::invokeMethod(), postDevice, Qt::QueuedConnection, QHttp::Reading, response, QHttp::Sending, setState(), state, QHttp::UnexpectedClose, and QHttp::WrongContentLength.

Referenced by setSock().

02325 {
02326     Q_Q(QHttp);
02327     if (state == QHttp::Closing)
02328         return;
02329 
02330     if (state == QHttp::Reading) {
02331         if (response.hasKey(QLatin1String("content-length"))) {
02332             // We got Content-Length, so did we get all bytes?
02333             if (bytesDone + q->bytesAvailable() != response.contentLength()) {
02334                 finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Wrong content length")), QHttp::WrongContentLength);
02335             }
02336         }
02337     } else if (state == QHttp::Connecting || state == QHttp::Sending) {
02338         finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Server closed connection unexpectedly")), QHttp::UnexpectedClose);
02339     }
02340 
02341     postDevice = 0;
02342     setState(QHttp::Closing);
02343     QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
02344 }

Here is the call graph for this function:

void QHttpPrivate::_q_slotBytesWritten ( qint64  numBytes  ) 

Definition at line 2403 of file qhttp.cpp.

References QIODevice::atEnd(), bytesDone, bytesTotal, QAbstractSocket::bytesToWrite(), closeConn(), QByteArray::data(), emit, n, QIODevice::pos(), postDevice, qWarning(), QIODevice::read(), QByteArray::resize(), QIODevice::size(), socket, and QIODevice::write().

Referenced by setSock().

02404 {
02405     Q_Q(QHttp);
02406     bytesDone += written;
02407     emit q->dataSendProgress(bytesDone, bytesTotal);
02408 
02409     if (!postDevice)
02410         return;
02411 
02412     if (socket->bytesToWrite() == 0) {
02413         int max = qMin<qint64>(4096, postDevice->size() - postDevice->pos());
02414         QByteArray arr;
02415         arr.resize(max);
02416 
02417         int n = postDevice->read(arr.data(), max);
02418         if (n <= 0) {
02419             qWarning("Could not read enough bytes from the device");
02420             closeConn();
02421             return;
02422         }
02423         if (postDevice->atEnd()) {
02424             postDevice = 0;
02425         }
02426 
02427         socket->write(arr, n);
02428     }
02429 }

Here is the call graph for this function:

void QHttpPrivate::_q_slotDoFinished (  ) 

Definition at line 2625 of file qhttp.cpp.

References QHttp::Connected, finishedWithSuccess(), setState(), state, and QHttp::Unconnected.

02626 {
02627     if (state == QHttp::Connected) {
02628         finishedWithSuccess();
02629     } else if (state != QHttp::Unconnected) {
02630         setState(QHttp::Unconnected);
02631         finishedWithSuccess();
02632     }
02633 }

Here is the call graph for this function:

void QHttpPrivate::_q_slotSendRequest (  ) 

Definition at line 2231 of file qhttp.cpp.

References _q_slotConnected(), QAbstractSocket::abort(), QObject::blockSignals(), QAbstractSocket::ConnectedState, QHttp::Connecting, QAbstractSocket::connectToHost(), finishedWithError(), QString::fromAscii(), QUrl::fromEncoded(), header, hostName, QString::isEmpty(), QString::isNull(), QHttpRequestHeader::majorVersion(), QHttpRequestHeader::method(), QHttpRequestHeader::minorVersion(), password, QHttpRequestHeader::path(), QAbstractSocket::peerName(), QAbstractSocket::peerPort(), port, proxyHost, proxyPassword, proxyPort, proxyUser, QUrl::resolved(), QUrl::setHost(), QUrl::setPort(), QHttpRequestHeader::setRequest(), setState(), QHttpHeader::setValue(), socket, QAbstractSocket::state(), QString::toAscii(), QUrl::toEncoded(), QString::toLatin1(), QHttp::UnknownError, and userName.

02232 {
02233     // Proxy support. Insert the Proxy-Authorization item into the
02234     // header before it's sent off to the proxy.
02235     if (!proxyHost.isEmpty()) {
02236         QUrl proxyUrl;
02237         proxyUrl.setScheme(QLatin1String("http"));
02238         proxyUrl.setHost(hostName);
02239         if (port && port != 80) proxyUrl.setPort(port);
02240         QString request = QString::fromAscii(proxyUrl.resolved(QUrl::fromEncoded(header.path().toLatin1())).toEncoded());
02241 
02242         header.setRequest(header.method(), request, header.majorVersion(), header.minorVersion());
02243 
02244         if (!proxyUser.isEmpty()) {
02245             QByteArray pass = proxyUser.toAscii();
02246             if (!proxyPassword.isEmpty()) {
02247                 pass += ':';
02248                 pass += proxyPassword.toAscii();
02249             }
02250             header.setValue(QLatin1String("Proxy-Authorization"), QLatin1String("Basic " + pass.toBase64()));
02251         }
02252     }
02253 
02254     // Username support. Insert the user and password into the query
02255     // string.
02256     if (!userName.isEmpty()) {
02257         QByteArray pass = userName.toAscii();
02258         if (!password.isEmpty()) {
02259             pass += ':';
02260             pass += password.toAscii();
02261         }
02262         header.setValue(QLatin1String("Authorization"), QLatin1String("Basic " + pass.toBase64()));
02263     }
02264 
02265     if (hostName.isNull()) {
02266         finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "No server set to connect to")),
02267                           QHttp::UnknownError);
02268         return;
02269     }
02270 
02271     // Do we need to setup a new connection or can we reuse an
02272     // existing one?
02273     if (socket->peerName() != hostName || socket->peerPort() != port
02274         || socket->state() != QTcpSocket::ConnectedState) {
02275         socket->blockSignals(true);
02276         socket->abort();
02277         socket->blockSignals(false);
02278 
02279         setState(QHttp::Connecting);
02280         if (proxyHost.isEmpty())
02281             socket->connectToHost(hostName, port);
02282         else
02283             socket->connectToHost(proxyHost, proxyPort);
02284     } else {
02285         _q_slotConnected();
02286     }
02287 
02288 }

Here is the call graph for this function:

int QHttpPrivate::addRequest ( QHttpRequest *   ) 

Definition at line 2203 of file qhttp.cpp.

References QList< T >::append(), QList< T >::count(), QHttpRequest::id, QMetaObject::invokeMethod(), pending, and Qt::QueuedConnection.

02204 {
02205     Q_Q(QHttp);
02206     pending.append(req);
02207 
02208     if (pending.count() == 1) {
02209         // don't emit the requestStarted() signal before the id is returned
02210         QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
02211     }
02212     return req->id;
02213 }

Here is the call graph for this function:

void QHttpPrivate::finishedWithSuccess (  ) 

Definition at line 2290 of file qhttp.cpp.

References _q_startNextRequest(), emit, QList< T >::first(), QHttpRequest::id, QList< T >::isEmpty(), pending, and QList< T >::removeFirst().

Referenced by _q_slotDoFinished().

02291 {
02292     Q_Q(QHttp);
02293     if (pending.isEmpty())
02294         return;
02295     QHttpRequest *r = pending.first();
02296 
02297     emit q->requestFinished(r->id, false);
02298     pending.removeFirst();
02299     delete r;
02300 
02301     if (pending.isEmpty()) {
02302         emit q->done(false);
02303     } else {
02304         _q_startNextRequest();
02305     }
02306 }

Here is the call graph for this function:

void QHttpPrivate::finishedWithError ( const QString &  detail,
int  errorCode 
)

Definition at line 2308 of file qhttp.cpp.

References emit, error, errorString, QList< T >::first(), QHttpRequest::id, QList< T >::isEmpty(), pending, and QList< T >::takeFirst().

Referenced by _q_slotClosed(), _q_slotError(), _q_slotReadyRead(), and _q_slotSendRequest().

02309 {
02310     Q_Q(QHttp);
02311     if (pending.isEmpty())
02312         return;
02313     QHttpRequest *r = pending.first();
02314 
02315     error = QHttp::Error(errorCode);
02316     errorString = detail;
02317     emit q->requestFinished(r->id, true);
02318 
02319     while (!pending.isEmpty())
02320         delete pending.takeFirst();
02321     emit q->done(true);
02322 }

Here is the call graph for this function:

void QHttpPrivate::init (  ) 

Definition at line 1536 of file qhttp.cpp.

References errorString, QMetaObject::invokeMethod(), and Qt::QueuedConnection.

01537 {
01538     Q_Q(QHttp);
01539     errorString = QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown error"));
01540     QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
01541 }

Here is the call graph for this function:

void QHttpPrivate::setState ( int   ) 

Definition at line 2673 of file qhttp.cpp.

References emit, qDebug(), and state.

Referenced by _q_slotClosed(), _q_slotConnected(), _q_slotDoFinished(), _q_slotError(), _q_slotReadyRead(), _q_slotSendRequest(), and closeConn().

02674 {
02675     Q_Q(QHttp);
02676 #if defined(QHTTP_DEBUG)
02677     qDebug("QHttp state changed %d -> %d", state, s);
02678 #endif
02679     state = QHttp::State(s);
02680     emit q->stateChanged(s);
02681 }

Here is the call graph for this function:

void QHttpPrivate::closeConn (  ) 

Definition at line 2683 of file qhttp.cpp.

References QAbstractSocket::close(), QHttp::Closing, QMetaObject::invokeMethod(), QIODevice::isOpen(), postDevice, Qt::QueuedConnection, setState(), socket, state, QAbstractSocket::state(), QHttp::Unconnected, and QAbstractSocket::UnconnectedState.

Referenced by _q_slotBytesWritten(), _q_slotError(), and _q_slotReadyRead().

02684 {
02685     Q_Q(QHttp);
02686     // If no connection is open -> ignore
02687     if (state == QHttp::Closing || state == QHttp::Unconnected)
02688         return;
02689 
02690     postDevice = 0;
02691     setState(QHttp::Closing);
02692 
02693     // Already closed ?
02694     if (!socket || !socket->isOpen()) {
02695         QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
02696     } else {
02697         // Close now.
02698         socket->close();
02699 
02700         // Did close succeed immediately ?
02701         if (socket->state() == QTcpSocket::UnconnectedState) {
02702             // Prepare to emit the requestFinished() signal.
02703             QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
02704         }
02705     }
02706 }

Here is the call graph for this function:

void QHttpPrivate::setSock ( QTcpSocket *  sock  ) 

Definition at line 2708 of file qhttp.cpp.

References _q_slotBytesWritten(), _q_slotClosed(), _q_slotConnected(), _q_slotError(), _q_slotReadyRead(), QObject::connect(), deleteSocket, QObject::disconnect(), error, SIGNAL, SLOT, and socket.

02709 {
02710     Q_Q(const QHttp);
02711 
02712     // disconnect all existing signals
02713     if (socket) socket->disconnect();
02714 
02715     // use the new QTcpSocket socket, or create one if socket is 0.
02716     deleteSocket = (sock == 0);
02717     socket = sock ? sock : new QTcpSocket();
02718 
02719     // connect all signals
02720     QObject::connect(socket, SIGNAL(connected()), q, SLOT(_q_slotConnected()));
02721     QObject::connect(socket, SIGNAL(disconnected()), q, SLOT(_q_slotClosed()));
02722     QObject::connect(socket, SIGNAL(readyRead()), q, SLOT(_q_slotReadyRead()));
02723     QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), q, SLOT(_q_slotError(QAbstractSocket::SocketError)));
02724     QObject::connect(socket, SIGNAL(bytesWritten(qint64)),
02725                      q, SLOT(_q_slotBytesWritten(qint64)));
02726 }

Here is the call graph for this function:


Member Data Documentation

QTcpSocket* QHttpPrivate::socket

Definition at line 105 of file qhttp.cpp.

Referenced by _q_slotBytesWritten(), _q_slotConnected(), _q_slotError(), _q_slotReadyRead(), _q_slotSendRequest(), closeConn(), setSock(), and ~QHttpPrivate().

int QHttpPrivate::reconnectAttempts

Definition at line 106 of file qhttp.cpp.

Referenced by _q_slotError().

bool QHttpPrivate::deleteSocket

Definition at line 107 of file qhttp.cpp.

Referenced by setSock(), and ~QHttpPrivate().

QList<QHttpRequest *> QHttpPrivate::pending

Definition at line 108 of file qhttp.cpp.

Referenced by _q_startNextRequest(), addRequest(), finishedWithError(), finishedWithSuccess(), and ~QHttpPrivate().

QHttp::State QHttpPrivate::state

Definition at line 110 of file qhttp.cpp.

Referenced by _q_slotClosed(), _q_slotConnected(), _q_slotDoFinished(), _q_slotError(), _q_slotReadyRead(), closeConn(), and setState().

QHttp::Error QHttpPrivate::error

Definition at line 111 of file qhttp.cpp.

Referenced by _q_startNextRequest(), finishedWithError(), and setSock().

QString QHttpPrivate::errorString

Definition at line 112 of file qhttp.cpp.

Referenced by _q_startNextRequest(), finishedWithError(), and init().

QString QHttpPrivate::hostName

Definition at line 114 of file qhttp.cpp.

Referenced by _q_slotSendRequest().

quint16 QHttpPrivate::port

Definition at line 115 of file qhttp.cpp.

Referenced by _q_slotSendRequest().

QByteArray QHttpPrivate::buffer

Definition at line 117 of file qhttp.cpp.

Referenced by _q_slotConnected(), and _q_slotReadyRead().

QIODevice* QHttpPrivate::toDevice

Definition at line 118 of file qhttp.cpp.

Referenced by _q_slotReadyRead().

QIODevice* QHttpPrivate::postDevice

Definition at line 119 of file qhttp.cpp.

Referenced by _q_slotBytesWritten(), _q_slotClosed(), _q_slotConnected(), _q_slotError(), and closeConn().

qint64 QHttpPrivate::bytesDone

Definition at line 121 of file qhttp.cpp.

Referenced by _q_slotBytesWritten(), _q_slotClosed(), _q_slotConnected(), and _q_slotReadyRead().

qint64 QHttpPrivate::bytesTotal

Definition at line 122 of file qhttp.cpp.

Referenced by _q_slotBytesWritten(), and _q_slotConnected().

qint64 QHttpPrivate::chunkedSize

Definition at line 123 of file qhttp.cpp.

Referenced by _q_slotReadyRead().

QHttpRequestHeader QHttpPrivate::header

Definition at line 125 of file qhttp.cpp.

Referenced by _q_slotConnected(), and _q_slotSendRequest().

bool QHttpPrivate::readHeader

Definition at line 127 of file qhttp.cpp.

Referenced by _q_slotReadyRead().

QString QHttpPrivate::headerStr

Definition at line 128 of file qhttp.cpp.

Referenced by _q_slotReadyRead().

QHttpResponseHeader QHttpPrivate::response

Definition at line 129 of file qhttp.cpp.

Referenced by _q_slotClosed(), and _q_slotReadyRead().

QRingBuffer QHttpPrivate::rba

Definition at line 131 of file qhttp.cpp.

Referenced by _q_slotReadyRead().

QString QHttpPrivate::userName

Definition at line 133 of file qhttp.cpp.

Referenced by _q_slotSendRequest().

QString QHttpPrivate::password

Definition at line 134 of file qhttp.cpp.

Referenced by _q_slotSendRequest().

QString QHttpPrivate::proxyHost

Definition at line 136 of file qhttp.cpp.

Referenced by _q_slotSendRequest().

int QHttpPrivate::proxyPort

Definition at line 137 of file qhttp.cpp.

Referenced by _q_slotSendRequest().

QString QHttpPrivate::proxyUser

Definition at line 138 of file qhttp.cpp.

Referenced by _q_slotSendRequest().

QString QHttpPrivate::proxyPassword

Definition at line 139 of file qhttp.cpp.

Referenced by _q_slotSendRequest().


The documentation for this class was generated from the following file:
Generated on Thu Mar 15 18:00:26 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1