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

QSslSocket does not work when the size of the read buffer is set

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.6.0
    • 4.5.0
    • Network
    • None
    • 760f221e7f1550ecc8198fb0c01c65ee13ded7f4

    Description

      If QSslSocket::setReadBufferSize() is called before the connexion is established, the socket does not read data after the first readAll(). A call to encryptedBytesAvailable() return a non null value, and the byte cannot be read.

      Here is an example to reproduce the problem:

      #include <QCoreApplication>
      #include <QSslSocket>
      #include <QTimer>
      #include <QtDebug>
      #include <QObject>
      
      class Transmitter : public QObject
      {
        Q_OBJECT
      
        public:
          Transmitter(QObject *parent=0);
          QTimer testTimer;
          QSslSocket *socket;
      
        public slots:
          void handleEncrypted();
          void handleData();
      };
      
      
      Transmitter::Transmitter(QObject *parent) : QObject(parent)
      {
        connect(&testTimer, SIGNAL(timeout()),
                this, SLOT(handleData()));
      
        socket = new QSslSocket(this);
        socket->setReadBufferSize(1000); // limit to 1 kb/sec
        connect(socket, SIGNAL(encrypted()),
                this, SLOT(handleEncrypted()));
      }
      
      void Transmitter::handleEncrypted()
      {
        qDebug() << "Connected.";
        socket->write("GET /mail/help/images/googlemail.gif HTTP/1.0\r\n\r\n");
        testTimer.start(1000);
      }
      
      void Transmitter::handleData()
      {
        QByteArray data = socket->readAll();
        //socket->flush(); work with flush
        qDebug() << "BytesAvailable:" << socket->bytesAvailable()
                 << "| EncryptedBytesAvailable:" << socket->encryptedBytesAvailable() << "size = " << data.size();
      }
      
      
      int main(int argc, char *argv[])
      {
      
        QCoreApplication qapp(argc, argv);
      
        qDebug() << "Connecting...";
        Transmitter *trans = new Transmitter;
        trans->socket->connectToHostEncrypted("mail.google.com", 443);
      
        return qapp.exec();
      }
      
      #include "main.moc"
      

      Attachments

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

        Activity

          People

            mgoetz Markus Goetz (Inactive)
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes