I have simple function that uses socket->peek() to check if whole HTTP header has been received. If not it returns to event loop and waits for next readyRead signal. Unfortunately on second or third call beginning of buffer returned by peek() gets overwritten by \0 bytes.
Simplest testcase (newConnection() is connected to QTcpServer::newConnection):
void httphandler::newConnection() { QTcpServer* server=static_cast<QTcpServer*>(sender()); QTcpSocket* s=server->nextPendingConnection(); connect(s,SIGNAL(readyRead()),this,SLOT(onReadyRead())); } void httphandler::onReadyRead() { QTcpSocket* clientSocket=static_cast<QTcpSocket*>(sender()); qDebug() << "Peeked " << clientSocket->bytesAvailable() << ": " << clientSocket->peek(128*1024).toHex(); }
Steps:
- use netcat to send 'abc\n' to socket
- program prints Peeked 4 : "6162630a"
- send 'def\n'
- program prints Peeked 8 : "6162630a6465660a"
- send 'ghi\n'
- program prints Peeked 12 : "000000006162630a6768690a"
Beginning of the buffer is overwritten by zeros. Previous Qt versions worked ok.