Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-14268

QTcpSocket::peek returns invalid data

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • 4.7.2
    • 4.7.0
    • Network
    • None
    • OpenSuse 11.3
      Qt version: libqt4-4.7.0-134.1.i586
    • bd287865d2b57395a340e85f1fac9b7ddff3ec14

      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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            mgoetz Markus Goetz (Inactive)
            qbast Jakub Stachowski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes