[Qt-interest] When QSocket::readAll() doesn't read all
David Boosalis
david.boosalis at gmail.com
Sat Mar 27 13:43:55 CET 2010
At issue is that on Kubuntu 9.10 (32Bit) QSocket::readAll() seems to not
read all the bytes available when I send a packet greater then 2K Bytes. I
have the read all in a slot that is tied to QSocket::readyRead() event.
I've tried the following to adjust for the missing data, but it fails.
MyNetworkThread::readyReadSlot()
{
QByteArray ba = serverSocket->readAll();
QByteArray ba2;
qDebug() << "New Packet: " << ba.size();
QDataStream in(&ba, QIODevice::ReadOnly);
in.setVersion(QDataStream::Qt_4_6);
quint32 packetSize = 0;
quint32 alteredBufSize = 0;
in >> pendingSize;
qDebug() << "Get packet size = " << pendingSize;
alteredBufSize = ba.size() - sizeof(quint32);
if (alteredBufSize < pendingSize) { // also tried it with while , but
results are the same
qDebug() << "wait for rest of packets, pending size = " << pendingSize;
ba.append(serverSocket->read(pendingSize - alteredBufSize));
qDebug() << "\tAfter append size = " << ba.size();
}
...
The serverSocket->read() seems to not be compatible with readAll. As I do
not get the desired result.
I know QSocket::readAll() has no guarentees as to what it returns, but it is
my only option as the code example given in Qt/clientNonBlocking gives
really really terrible performance on Windows XP. (Using Qt 4.6.2). The
data feed comes in fairly fast. Everything works as advertised for small
packets
The example code looks like this:
qint64 bytesAvailable = serverSocket->bytesAvailable();
if (blockSize == 0) {
qDebug() << "First read...";
if (bytesAvailable < sizeof(quint32)) {
qDebug() << "\tNot enough bytes, return";
return;
}
in >> blockSize;
qDebug() << "blockSize = " << blockSize;
}
if (bytesAvailable < (qint64) blockSize) {
qDebug() << "Block size: " << blockSize;
qDebug() << "****** Not enough bytes available: " << bytesAvailable;
return;
}
...
Any ideas how to resolve the issue very much appreciated.
-David.
PS
Does anyone know if QSockets is getting any upgrades or TLC in 4.7 ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100327/2f482a00/attachment.html
More information about the Qt-interest-old
mailing list