Commit fea13a44 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlDebugger: parsing packets iteratively in the communication protocol

Reviewed-by: Kai Koehne
parent 72e65485
......@@ -153,46 +153,44 @@ public Q_SLOTS:
void readyToRead()
{
if(-1 == inProgressSize) {
// We need a size header of sizeof(qint32)
if(sizeof(qint32) > (uint)dev->bytesAvailable())
return;
// Read size header
int read = dev->read((char *)&inProgressSize, sizeof(qint32));
Q_ASSERT(read == sizeof(qint32));
Q_UNUSED(read);
// Check sizing constraints
if(inProgressSize > maxPacketSize) {
QObject::disconnect(dev, SIGNAL(readyRead()),
this, SLOT(readyToRead()));
QObject::disconnect(dev, SIGNAL(aboutToClose()),
this, SLOT(aboutToClose()));
QObject::disconnect(dev, SIGNAL(bytesWritten(qint64)),
this, SLOT(bytesWritten(qint64)));
dev = 0;
emit invalidPacket();
return;
}
inProgressSize -= sizeof(qint32);
while(true) {
// Need to get trailing data
readyToRead();
} else {
inProgress.append(dev->read(inProgressSize - inProgress.size()));
if(inProgressSize == inProgress.size()) {
// Packet has arrived!
packets.append(inProgress);
inProgressSize = -1;
inProgress.clear();
if(-1 == inProgressSize) {
// We need a size header of sizeof(qint32)
if(sizeof(qint32) > (uint)dev->bytesAvailable())
return;
// Read size header
int read = dev->read((char *)&inProgressSize, sizeof(qint32));
Q_ASSERT(read == sizeof(qint32));
Q_UNUSED(read);
// Check sizing constraints
if(inProgressSize > maxPacketSize) {
QObject::disconnect(dev, SIGNAL(readyRead()),
this, SLOT(readyToRead()));
QObject::disconnect(dev, SIGNAL(aboutToClose()),
this, SLOT(aboutToClose()));
QObject::disconnect(dev, SIGNAL(bytesWritten(qint64)),
this, SLOT(bytesWritten(qint64)));
dev = 0;
emit invalidPacket();
return;
}
inProgressSize -= sizeof(qint32);
} else {
inProgress.append(dev->read(inProgressSize - inProgress.size()));
emit readyRead();
if(inProgressSize == inProgress.size()) {
// Packet has arrived!
packets.append(inProgress);
inProgressSize = -1;
inProgress.clear();
// Need to get trailing data
readyToRead();
emit readyRead();
} else
return;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment