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

qmqttconnection doesn't work for already opened websockets

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.10.1
    • Fix Version/s: 5.11.0
    • Component/s: MQTT
    • Labels:
      None
    • Environment:
      Suse 42.3

      gcc v7.2.1
    • Commits:
      434ed837417ed0692bc55fc882d918a47a6b7e71

      Description

      commit cd1d60ec71836d6c4e9cbfbf344ef9334a22cdc4 by Maurice Kalinowski changed qmqttconnection.cpp and added the following to qmqttclient.cpp:

       

      // Once transport has connected, it will invoke
      // QMqttConnection::sendControlConnect to
      // handshake with the broker

       

      however, when the mqtt client is used over a custom websocket based on QIODevice (just like in the by Qt provided mqtt websocket example), this doesn't work anymore, because the following code immediately returns true when the iodevice is already open. Because sendControlConnect() doesn't get called, the mqtt client never connects.

       

      if (m_transportType == QMqttClient::IODevice) {
       if (m_transport->isOpen())
       return true;
       if (!m_transport->open(QIODevice::ReadWrite)) {
        qWarning("Could not open Transport IO device");  
        m_internalState = BrokerDisconnected;
        return false;
       }
      
       return sendControlConnect();
      }
      
      

       Though it might not be the preferred way of solving the problem, the following works:

      diff -u -r git-qt5-qtmqtt-orig/src/mqtt/qmqttconnection.cpp git-qt5-qtmqtt/src/mqtt/qmqttconnection.cpp
      --- git-qt5-qtmqtt-orig/src/mqtt/qmqttconnection.cpp 2018-03-08 16:16:43.974246846 +0100
      +++ git-qt5-qtmqtt/src/mqtt/qmqttconnection.cpp 2018-03-08 16:17:39.353350689 +0100
      @@ -125,7 +125,7 @@
       
       if (m_transportType == QMqttClient::IODevice) {
       if (m_transport->isOpen())
      - return true;
      + return sendControlConnect();
       
       if (!m_transport->open(QIODevice::ReadWrite)) {
       qWarning("Could not open Transport IO device");

       

        Attachments

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

          Activity

            People

            Assignee:
            mkalinow Maurice Kalinowski
            Reporter:
            mr.gadgets Frank van Vugt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes