Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT with AMQP-CPP library
Forum Updated to NodeBB v4.3 + New Features

QT with AMQP-CPP library

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M maragr

    @ChrisW67
    Looks like MyTcpHandler::monitor got called 3 times in the beginning with 2 errors and then once it found a successful connection, it doesn't get called again.
    However, the MyTcpHandler::onSocketActivated got called multiple times in the beginning and then "precisely" 6 times before every message. Below is the log.

    QML debugging is enabled. Only use this in a safe environment.
    Reached monitor
    36
    Reached process
    Reached monitor
    40
    Reached monitor
    36
    QSocketNotifier: Invalid socket 36 and type 'Read', disabling...
    Reached process
    Reached process
    QSocketNotifier: Invalid socket 36 and type 'Read', disabling...
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    "amq.ctag-eS23ghYSNLT_UywYko8agg"
    Threaded rendering is not optimal in the Mapbox GL plugin.
    [ INFO ]  "{QSGRenderThread}[General]: GPU Identifier: Mesa Intel(R) UHD Graphics (TGL GT1)"
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    1
    < Print of message 1 body>
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    2
    < Print of message 2 body>
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    Reached process
    .......
    
    SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #5

    Hi,

    That's where your issue lies. You don't delete the previous socket notifier before creating a new one. So you have now three active notifiers.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    M 1 Reply Last reply
    1
    • SGaistS SGaist

      Hi,

      That's where your issue lies. You don't delete the previous socket notifier before creating a new one. So you have now three active notifiers.

      M Offline
      M Offline
      maragr
      wrote on last edited by maragr
      #6

      @SGaist So how do I catch any errors and delete the socket notifiers that are not required?

      SGaistS 1 Reply Last reply
      0
      • M maragr

        @SGaist So how do I catch any errors and delete the socket notifiers that are not required?

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #7

        You should keep track of the file descriptors and if already in use, don't create a new QSocketNotifier for it.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        2
        • SGaistS SGaist

          You should keep track of the file descriptors and if already in use, don't create a new QSocketNotifier for it.

          M Offline
          M Offline
          maragr
          wrote on last edited by maragr
          #8

          @SGaist Not sure if that is the case. Because the QSocketNotifier: Invalid socket 36 and type 'Read', disabling... shows that the invalid socket is disabled. So it might not be firing the activated signal. I printed out the file descriptor when onSocketActivated gets triggered and all of them are called by the same fd. (in this case fd=40). What am I missing?

          Same behavior is observed even when I keep track of all file descriptors and only create new ones when they are not in use. The only difference with this addition is that now the error QSocketNotifier: Invalid socket 36 and type 'Read', disabling... only appears once.

          JonBJ 1 Reply Last reply
          0
          • M maragr

            @SGaist Not sure if that is the case. Because the QSocketNotifier: Invalid socket 36 and type 'Read', disabling... shows that the invalid socket is disabled. So it might not be firing the activated signal. I printed out the file descriptor when onSocketActivated gets triggered and all of them are called by the same fd. (in this case fd=40). What am I missing?

            Same behavior is observed even when I keep track of all file descriptors and only create new ones when they are not in use. The only difference with this addition is that now the error QSocketNotifier: Invalid socket 36 and type 'Read', disabling... only appears once.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #9

            @maragr
            Hi. Don't know if I can help butting in. Seems I don't understand what you are asking as well as the others do. Which issue are you trying to address now?

            • Multiple calls to onSocketActivated() when no data?
            • Message Invalid socket ...?
            • Keeping track of which file descriptor numbers you have placed notifiers on?
            • Something else?
            M 1 Reply Last reply
            0
            • JonBJ JonB

              @maragr
              Hi. Don't know if I can help butting in. Seems I don't understand what you are asking as well as the others do. Which issue are you trying to address now?

              • Multiple calls to onSocketActivated() when no data?
              • Message Invalid socket ...?
              • Keeping track of which file descriptor numbers you have placed notifiers on?
              • Something else?
              M Offline
              M Offline
              maragr
              wrote on last edited by
              #10

              @JonB i am only trying to address why the onSocketActivated function is being called multiple times even when there is no data?

              (The comments above indicated that it might be an issue with creating many socket notifiers per file descriptor. But resolving this by tracking file descriptors and socket notifiers does not solve the above issue. Hope this helps!)

              JonBJ 1 Reply Last reply
              0
              • M maragr

                @JonB i am only trying to address why the onSocketActivated function is being called multiple times even when there is no data?

                (The comments above indicated that it might be an issue with creating many socket notifiers per file descriptor. But resolving this by tracking file descriptors and socket notifiers does not solve the above issue. Hope this helps!)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #11

                @maragr
                OK, now I know where we are :)

                The QSocketNotifier uses Linux select() call on the file descriptor. I really think you should assume if it says there is a Read data available when it's called there is. Assuming we are indeed not talking about multi-notifiers per descriptor, then I would question how you get your assertion/evidence that no data is there.

                M 1 Reply Last reply
                0
                • JonBJ JonB

                  @maragr
                  OK, now I know where we are :)

                  The QSocketNotifier uses Linux select() call on the file descriptor. I really think you should assume if it says there is a Read data available when it's called there is. Assuming we are indeed not talking about multi-notifiers per descriptor, then I would question how you get your assertion/evidence that no data is there.

                  M Offline
                  M Offline
                  maragr
                  wrote on last edited by maragr
                  #12

                  @JonB Hmm that is a good question. My assertion was based on the fact that onSocketActivated was called 6 times before the consume.onReceived function was triggered from the AMQP-CPP library, thus reading the available message. But now, I think there might be something with this function _conn->process(fd, AMQP::readable); (called within the onSocketActivated slot) from AMQP-CPP library that does not register the read call right away once activated signal is received.

                  Is this a correct assumption that QSocketNotifier will keep triggering the activated signal until the data is read from the socket?

                  JonBJ 1 Reply Last reply
                  0
                  • M maragr

                    @JonB Hmm that is a good question. My assertion was based on the fact that onSocketActivated was called 6 times before the consume.onReceived function was triggered from the AMQP-CPP library, thus reading the available message. But now, I think there might be something with this function _conn->process(fd, AMQP::readable); (called within the onSocketActivated slot) from AMQP-CPP library that does not register the read call right away once activated signal is received.

                    Is this a correct assumption that QSocketNotifier will keep triggering the activated signal until the data is read from the socket?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #13

                    @maragr
                    I was about to say "no", I thought it would only raise the signal whenever new data arrived, even if old data was left there presently unread. I believe that is what Qt's normal socket readyRead() behaves:

                    This signal is emitted once every time new data is available for reading from the device. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device

                    However, I am not sure that will be case for QSocketNotifier using select() (or maybe poll()) call. That returns whenever any data is available on a file descriptor (so that a read() will complete), I don't think it would know that new data has arrived rather than old data is already lying there.

                    Unless one or both of these reads the data into a buffer when it first arrives, so that the descriptor is clear for future reads.

                    Truth is I don't know, you would have to test.

                    M 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @maragr
                      I was about to say "no", I thought it would only raise the signal whenever new data arrived, even if old data was left there presently unread. I believe that is what Qt's normal socket readyRead() behaves:

                      This signal is emitted once every time new data is available for reading from the device. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device

                      However, I am not sure that will be case for QSocketNotifier using select() (or maybe poll()) call. That returns whenever any data is available on a file descriptor (so that a read() will complete), I don't think it would know that new data has arrived rather than old data is already lying there.

                      Unless one or both of these reads the data into a buffer when it first arrives, so that the descriptor is clear for future reads.

                      Truth is I don't know, you would have to test.

                      M Offline
                      M Offline
                      maragr
                      wrote on last edited by maragr
                      #14

                      @JonB QSocketNotifier fires until there is data to read on the socket. Marking this as solved.

                      1 Reply Last reply
                      0
                      • M maragr has marked this topic as solved on

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved