[zeromq-dev] Problem with zeromq and large messages

Laurent Alebarde l.alebarde at free.fr
Fri Jan 3 19:05:32 CET 2014


At first glance, you are mixing up in your mind multi-part messages that 
can be managed with "more", with the problem of the need of several 
reads when you read a certain amount of bytes lesser than the message sent.

So you need an inner loop that reads until rc < 0. The last read will 
have rc <= BUFFER_SIZE, and an outer loop for multipart messages with 
"more" management.



Le 03/01/2014 18:48, Brant Merryman a écrit :
> I have been using zeromq in my application and I've been having some 
> problems with it.
>
> Sometimes I need to send large messages. I have code that works kind 
> of like this:
>
>     char eventBuffer[BUFFER_SIZE];
>
>     for (int more = 1; more; ) {
>     rc = zmq_recv(socket, eventBuffer, BUFFER_SIZE, 0);
>     if (rc > 0) {
>     <accumulate the data in the event buffer>
>     size_t moreSz = sizeof(int);
>     zmq_getsockopt(socket, ZMQ_RCVMORE, &more, &moreSz);
>     } else {
>     printf("zmq_recv failed: %d\n", rc);
>     more = 0;
>     }
>     }
>
>     <handle the accumulated data>
>
>
>
> The process that is sending the data uses code like this:
>
>     rc = zmq_send(socket, data, data_length, 0);
>     if (rc <= 0) {
>     printf("zmq_send failed: %d\n", rc);
>     }
>
>
> The problem is that when the data being sent is less than BUFFER_SIZE 
> -- no problem. But when the data sent is larger than BUFFER_SIZE, the 
> zmq_recv call gets the same number of bytes that was sent. What I was 
> /expecting/ was that the number of bytes returned would be BUFFERSIZE 
> and that zmq_getsockopt would result in *more* being 1 and we would 
> repeat that data_length/BUFFER_SIZE times and then once more for the 
> remaining data and then more would go to 0 and we would exit the loop.
>
> How the heck is this supposed to work? What am I doing wrong?
>
> Thanks.
>
> Brant
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

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


More information about the zeromq-dev mailing list