- // don't try to read more data if we're already closing
- if (socket()->state() != QAbstractSocket::ConnectedState)
- return;
-
- QByteArray data;
- while (readSocketData(data)) {
- // data contains always a serialized QVector<QVariant>
- QDataStream stream(data);
- stream.setVersion(QDataStream::Qt_4_2);
- QVariantList list;
- stream >> list;
- if (stream.status() != QDataStream::Ok) {
- close("Peer sent corrupt data, closing down!");
- return;
- }
-
- // if no sigproxy is set, we're in handshake mode
- if (!signalProxy())
- handleHandshakeMessage(list);
- else
- handlePackedFunc(list);
- }
-}
-
-
-bool DataStreamPeer::readSocketData(QByteArray &data)
-{
- if (_blockSize == 0) {
- if (socket()->bytesAvailable() < 4)
- return false;
- // the block size is part of QByteArray's serialization format, so we don't actually read it now...
- socket()->peek((char*)&_blockSize, 4);
- _blockSize = qFromBigEndian<quint32>(_blockSize) + 4; // ... but of course we have to add its size to the total size of the block
- }
-
- if (_blockSize > 1 << 22) {
- close("Peer tried to send package larger than max package size!");
- return false;
- }
-
- if (_blockSize == 0) {
- close("Peer tried to send 0 byte package!");
- return false;
- }
-
- if (socket()->bytesAvailable() < _blockSize) {
- emit transferProgress(socket()->bytesAvailable(), _blockSize);
- return false;
- }
-
- emit transferProgress(_blockSize, _blockSize);
-
- _stream >> data;
- _blockSize = 0;
-
- if (_stream.status() != QDataStream::Ok) {