[zeromq-dev] Anyone managed to use zeromq with Qt (QSocketNotifier) ?

Maciej Gajewski maciej.gajewski0 at gmail.com
Tue Sep 20 08:59:06 CEST 2011


I did it and it works nicely on Linux and Windows.

You need to disable the notifier before calling ZMQ_EVENTS (and
reading the message if available) and enable if afterwards.

Pseudocode:

void OnSocketReadable(zmqsocket, notifier)
{
    notifier.setEnabled(false);
    CheckForEventsAndRead(zmqsocket);
    notifier.setEnabled(true);
}

bool HasIncoming(zmqsocket)
{
    qint32 events = 0;
    std::size_t eventsSize = sizeof(events);
    zmqsocket.getsockopt(ZMQ_EVENTS, &events, &eventsSize);
    return (events & ZMQ_POLLIN);
}

void CheckForEventsAndRead(zmqsocket)
{
    if (HasIncoming(zmqsocket))
        ReadMessage(zmqsocket);
}

cheers,

Maciek

On 19 September 2011 19:41, Gaspard Bucher <gaspard at teti.ch> wrote:
> Hi list !
> I am trying to use zeromq with a Qt application and I want to avoid having
> multiple threads
> so I tried to use ZMQ_FD and pass this to QSocketNotifier but only the first
> message is
> signaled. My guess is that zmq does not keep the file descriptor in
> read-ready state but
> just signals the first element ?
> Pseudo-code:
> 1. get zmq fd
> 2. create QSocketNotifier with 'Read' events
> 3. app exec
> ..
> 4. first (or many) messages arrive
> 5. ---> QSocketNotifier fires
> 6. get 1 message
> 7. wait for QSocketNotifier to fire again
> 8. .... never happens
> My guess is that there is something I do not understand regarding the ZMQ_FD
> file descriptor.
> Maybe it only retriggers "read-ready" if the queue has been emptied ?
> Thanks for your help,
>                                                                Gaspard
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>



More information about the zeromq-dev mailing list