Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

bool QAbstractSocket::waitForReadyRead ( int  msecs = 30000 ) [virtual, inherited]

This function blocks until data is available for reading and the {QIODevice::}{readyRead()} signal has been emitted. The function will timeout after msecs milliseconds; the default timeout is 30000 milliseconds.

The function returns true if the readyRead() signal is emitted and there is data available for reading; otherwise it returns false (if an error occurred or the operation timed out).

See also:

Reimplemented from QIODevice.

Reimplemented in QSslSocket.

Definition at line 1672 of file qabstractsocket.cpp.

References QAbstractSocket::close(), QTime::elapsed(), QAbstractSocket::error(), QIODevice::errorString(), QIODevice::setErrorString(), QTime::start(), QAbstractSocket::state(), and QAbstractSocket::waitForConnected().

Referenced by QSocks5SocketEngine::bind(), and FortuneThread::run().

    qDebug("QAbstractSocket::waitForReadyRead(%i)", msecs);

    // require calling connectToHost() before waitForReadyRead()
    if (state() == UnconnectedState) {
        /* If all you have is a QIODevice pointer to an abstractsocket, you cannot check
           this, so you cannot avoid this warning. */
//        qWarning("QAbstractSocket::waitForReadyRead() is not allowed in UnconnectedState");
        return false;

    QTime stopWatch;

    // handle a socket in connecting state
    if (state() == HostLookupState || state() == ConnectingState) {
        if (!waitForConnected(msecs))
            return false;

    forever {
        bool readyToRead = false;
        bool readyToWrite = false;
        if (!d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(),
                                               qt_timeout_value(msecs, stopWatch.elapsed()))) {
            d->socketError = d->socketEngine->error();
            qDebug("QAbstractSocket::waitForReadyRead(%i) failed (%i, %s)",
                   msecs, d->socketError, errorString().toLatin1().constData());
            emit error(d->socketError);
            if (d->socketError != SocketTimeoutError)
            return false;

        if (readyToRead) {
            if (d->canReadNotification())
                return true;

        if (readyToWrite)

        if (state() != ConnectedState)
            return false;
    return false;

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index