cleanup frame processing and payload alignment
- remove a level of indentation making frame processing easier to read - use qFromBigEndian(const uchar *src) to ensure alignment of payload size
This commit is contained in:
parent
4ed42b74d5
commit
1eea37cb6f
|
|
@ -189,14 +189,14 @@ void ClientPrivate::_q_socketError(QAbstractSocket::SocketError error)
|
|||
void ClientPrivate::_q_readyRead()
|
||||
{
|
||||
while (socket->bytesAvailable() >= Frame::HEADER_SIZE) {
|
||||
char headerData[Frame::HEADER_SIZE];
|
||||
socket->peek(headerData, Frame::HEADER_SIZE);
|
||||
// FIXME: This is not the correct way of reading payloadSize
|
||||
// gcc: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
|
||||
const quint32 payloadSize = qFromBigEndian<quint32>(*(quint32*)&headerData[3]);
|
||||
unsigned char headerData[Frame::HEADER_SIZE];
|
||||
socket->peek((char*)headerData, Frame::HEADER_SIZE);
|
||||
const quint32 payloadSize = qFromBigEndian<quint32>(headerData + 3);
|
||||
const qint64 readSize = Frame::HEADER_SIZE + payloadSize + Frame::FRAME_END_SIZE;
|
||||
|
||||
if (socket->bytesAvailable() >= readSize) {
|
||||
if (socket->bytesAvailable() < readSize)
|
||||
return;
|
||||
|
||||
buffer.resize(readSize);
|
||||
socket->read(buffer.data(), readSize);
|
||||
const char *bufferData = buffer.constData();
|
||||
|
|
@ -271,9 +271,6 @@ void ClientPrivate::_q_readyRead()
|
|||
close(FrameError, "invalid frame type");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue