[zeromq-dev] problem with zmsg_recv_nowait
Pieter Hintjens
ph at imatix.com
Wed Mar 18 14:20:33 CET 2015
The code for that method, in 2.2.0, looks very suspect. My advice is
to use the 3.0.0 release or github master.
On Wed, Mar 18, 2015 at 2:06 PM, Arturo S. Garcia <artgarcia at gmail.com> wrote:
> Hi All,
>
> I am using czmq-2.2.0, zeromq-4.0.5 and libsodium-1.0.2.
>
> I am tying to send a message using a publisher node and receive it using
> zmsg_recv_nowait. The thing is that I do not know if I am doing something
> wrong... Here is the code:
>
> Publiser:
>
> std::string data ("test");
> zmsg_t *mess = zmsg_new();
> zmsg_addmem(mess, data.c_str(), data.size());
> zmsg_send (&mess, _pub);
>
> Subscriber:
>
> zmsg_t *message2 = zmsg_recv_nowait (_subs);
> if (message2)
> {
> zframe_t *content = zmsg_pop (message2);
> // get message
> char* char_msg = zframe_strdup(content);
> data = std::string(char_msg,zframe_size(content));
> printf("Response: '%s'\n", data.c_str());
> }
>
> The problem is that I never receive a message in the subscriber. If I change
> to zmsg_recv, then I am able to receive them. Is it possible that
> zmsg_recv_nowait is not working properly? or I am using it in a wrong way?
> Moreover, changing from zmsg_recv_nowait to zstr_recv_nowait also works
> fine...
>
> I have modified the code of zmsg_recv_nowait in zmsg.c when the last message
> frame is received by including frames++ because I noticed that the message
> was actually received, but discarded becasue the frame counter is not
> increased. Is this a mistake or this function was intended to be used with
> more than one frame only?
>
> Here is the modified zmsg_recv_nowait:
> zmsg_t *
> zmsg_recv_nowait (void *zocket)
> {
> assert (zocket);
> int frames = 0;
> zmsg_t *self = zmsg_new ();
> if (!self)
> return NULL;
>
> while (true) {
> zframe_t *frame = zframe_recv_nowait (zocket);
> if (!frame) {
> zmsg_destroy (&self);
> break; // Interrupted or terminated
> }
> if (zmsg_append (self, &frame)) {
> zmsg_destroy (&self);
> break;
> }
> if (!zsocket_rcvmore (zocket))
> {
> frames++;
> break; // Last message frame
> }
> frames++;
> }
> return frames > 0 ? self : NULL;
> }
>
> Any ideas? Thanks in advance.
>
> Regards,
> Arturo
>
> _______________________________________________
> 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