简体   繁体   中英

QSslSocket waitForReadyRead does not appear to be working

Here is a small block of code above a read() statement in a synchronous TCP client that I've written.

    std::cout << "available? " << socket->bytesAvailable() << std::endl;
    socket->waitForReadyRead();
    std::cout << "reading..." << std::endl;
    bytesRead = socket->read(message + totalBytesRead, messageSize - totalBytesRead);

The following line:

socket->bytesAvailable()

returns 4, so there is obviously data available to be read. The problem that I'm having is that waitForReadyRead() is blocking until the default timeout of 30 seconds. Read() then proceeds to read 0 bytes on the following line.

So if there are bytes available to be read, why does waitForReadyRead() block

from QIODevice::waitForReadyRead documentation:

Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. If msecs is -1, this function will not time out.

Returns true if new data is available for reading; otherwise returns false (if the operation timed out or if an error occurred).

The best why to handle network connection is to use signal/slots mechanism (the asynchronous why)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM