diff options
author | Christiaan Janssen <christiaan.janssen@nokia.com> | 2011-04-15 14:26:44 (GMT) |
---|---|---|
committer | Christiaan Janssen <christiaan.janssen@nokia.com> | 2011-05-30 11:08:32 (GMT) |
commit | a5926145407103ed2e3e6ee0369358709a50c551 (patch) | |
tree | e93437df8d6e99030e976819c883ac8888512e07 | |
parent | 10f16bc55b9e5535bc3353260f97a32e18d70cf1 (diff) | |
download | Qt-a5926145407103ed2e3e6ee0369358709a50c551.zip Qt-a5926145407103ed2e3e6ee0369358709a50c551.tar.gz Qt-a5926145407103ed2e3e6ee0369358709a50c551.tar.bz2 |
QmlDebugger: parsing packets iteratively in the communication protocol
Reviewed-by: Kai Koehne
(reapplied commit fea13a449c59690ae7b7f43aa64f50c0a290a2cf from qtcreator)
Change-Id: I0c78188994029b2ac7daa3d59182566c5ec6c8b5
-rw-r--r-- | src/declarative/debugger/qpacketprotocol.cpp | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp index c24df61..77c5f44 100644 --- a/src/declarative/debugger/qpacketprotocol.cpp +++ b/src/declarative/debugger/qpacketprotocol.cpp @@ -164,47 +164,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(); - waitingForPacket = false; + if (inProgressSize == inProgress.size()) { + // Packet has arrived! + packets.append(inProgress); + inProgressSize = -1; + inProgress.clear(); - // Need to get trailing data - readyToRead(); + emit readyRead(); + } else + return; } } } |