[zeromq-dev] C Based ZeroMQ Aggregation Server Problems...

Chuck Remes cremes.devlist at mac.com
Mon Oct 17 22:36:00 CEST 2011


On Oct 17, 2011, at 3:12 PM, Matthew West wrote:

>     while (1) {
>         // Read message contents
>         zmq_poll (items,poll_size,-1);
>         if(items [0].revents & ZMQ_POLLIN) {
>             zmq_msg_t buf;
>             zmq_msg_init (&buf);
>             if(zmq_recv(sink,&buf,0)) {
>                 printf("WARNING recv failure\n");
>                 continue;
>             }
>             int size = zmq_msg_size(&buf);
>             char *string = malloc(size+1);
>             memcpy(string,zmq_msg_data(&buf),size);
>             string[size] = 0;
>             zmq_msg_close(&buf);
> 
>             zmq_msg_t msg;
>             zmq_msg_init_data(&msg,string,size,my_free,NULL);
>             zmq_send(publisher,&msg,0);
>             zmq_msg_close(&msg);
>         }
>     }

I don't see the point in polling the PULL socket. Just call zmq_recv() on your sink and it will block until a message is received.

Try that and see if it works. If it does, then the culprit is zmq_poll().

Also, you don't need to memcpy() the buf. You can send it out to your publisher directly without any copy.

cr

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111017/dd856b91/attachment.htm>


More information about the zeromq-dev mailing list