[zeromq-dev] Query on zmq_poll API

Goswin von Brederlow goswin-v-b at web.de
Tue Aug 19 13:56:20 CEST 2014


On Mon, Aug 18, 2014 at 05:14:19PM -0700, Badhrinath Manoharan wrote:
> Hi,
> 
> I have the following topology
> 
> Client ---> Broker ----> Server
> 
> Both the client and server are sockets of type ZMQ_REQ while the Broker has
> a socket connected to client and another Socket Connected to Server both
> are of type ZMQ_BROKER.

Do you mean ZMQ_REQ, ZMQ_ROUTER, ZMQ_DEALER and ZMQ_REP?

Otherwise your topology is different:

Client ---> Broker <---- Server

>     void *frontend = zmq_socket (context, ZMQ_ROUTER);
>     void *backend = zmq_socket (context, ZMQ_ROUTER);
> 
>     zmq_bind(frontend, "ipc:///users/badmanoh/frontend.ipc");
>     zmq_bind(backend, "ipc:///users/badmanoh/backend.ipc");
> 
>     poll_items[0].socket = frontend;
>     poll_items[0].fd = 0;
>     poll_items[0].events = ZMQ_POLLIN;
>     poll_items[0].revents = 0;
> 
>     poll_items[0].socket = backend;
>     poll_items[0].fd = 0;
>     poll_items[0].events = ZMQ_POLLIN;
>     poll_items[0].revents = 0;
> 
>     while (1) {
>         ret = zmq_poll(poll_items, 2, -1);
>         if (ret == -1) {
>             printf("zmq_poll returned -1. Error: %d\n", errno);
>             return 0;
>         }
>         if (poll_items[0].revents & ZMQ_POLLIN) {
>         }
>         if (poll_items[0].revents & ZMQ_POLLIN) {
>         }
> }
> 
> On the broker code, I have a zmq_poll(poll_items, 2, -1) on a while loop. I
> see the zmq_poll notifying the first message from each socket. However
> subsequent messages from both the client or server sockets are not at all
> returned and the zmq_poll just stays in an infinite loop. Could you let us
> know if I am missing anything? Do I need to reset the revents value as part
> of the first notification?
> 
> Thanks
> Badhri

After getting the initial message do you send the right reply back? A
REQ socket has a strickt send/recv pattern.

When you post source don't remove anything. Always post a working
source that shows your problem. The bits you cut out are often the
bits that are broken.

MfG
	Goswin



More information about the zeromq-dev mailing list