[zeromq-dev] Problem with zeromq and large messages

Pieter Hintjens ph at imatix.com
Fri Jan 3 20:22:18 CET 2014


Please read the man page for zmq_recv_send and zmq_msg_recv. It's
pretty clearly explained. http://api.zeromq.org/3-2:zmq-msg-send

On Fri, Jan 3, 2014 at 6:48 PM, Brant Merryman <brantm at phmgmt.com> wrote:
> 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
>



More information about the zeromq-dev mailing list