[zeromq-dev] Checking for errors on zmq_poll: is it correct?

Michel Pelletier pelletier.michel at gmail.com
Thu Aug 16 19:11:46 CEST 2012


It looks like you are assigning zerr twice and not checking the return
from poll.  I don't think zmq_error() will return a sensible value
unless zmq_poll returns -1.

-Michel

On Thu, Aug 16, 2012 at 9:49 AM, erupter at libero.it <erupter at libero.it> wrote:
> Hello.
>
> I'm a newbie still playing around trying to grasp 0mq.
>
>
> I'm re-writing the first example with polling.
>
> So my REP has become
>
>
> zmq_pollitem_t local_zmq_sockets[1];
>
>
> int main (void)
> {
>     zmq_msg_t request;
>     void *context = zmq_init (1);
>     const char * chptr = 0;
>     int zerr = 0;
>     // Socket to talk to clients
>     void *responder = zmq_socket (context, ZMQ_REP);
>     zmq_bind (responder, "tcp://*:5555");
>     s_catch_signals ();
>     local_zmq_sockets[0].socket = responder;
>     local_zmq_sockets[0].events = ZMQ_POLLIN;
>
>     while (1) {
>         // Wait for next request from client
>
>
>         zerr = zmq_poll(local_zmq_sockets,1,5);
>         if (local_zmq_sockets[0].revents & ZMQ_POLLIN) {
>             zmq_msg_init (&request);
>             zmq_recv (responder, &request, 0);
>             zmq_msg_close(&request);
>         }
>         zerr = zmq_errno();
>         if (zerr != 0)
>         {       chptr = zmq_strerror(zerr);
>                 printf ("\n%s\n", chptr);
>         }
>
>         zmq_msg_close (&request);
>         if (s_interrupted) {
>             printf ("\nSIGTERM interrupt received, killing server…\n");
>             break;
>         }
>         // Do some 'work'
>         sleep (1);
>
>         // Send reply back to client
>         zmq_msg_t reply;
>         zmq_msg_init_size (&reply, 5);
>         memcpy (zmq_msg_data (&reply), "Prova", 5);
>         zmq_send (responder, &reply, 0);
>         zmq_msg_close (&reply);
>     }
>     // We never get here but if we did, this would be how we end
>     zmq_close (responder);
>     zmq_term (context);
>     return 0;
> }
>
>
> Now the fact is that when it's sitting idly waiting for a REQ, the error
> number reported after the POLL call is always 11, and the associated string
> is
>
> "Resource temporarily unavailable"
>
>
> I don't get this: should I *not* check for errors after zmq_poll???
> I expected a 0 after a correct poll.
>
> Even when a message comes in, it still gives the same error code.
>
>
> Can anyone please explaing this behviour to me?
> Thanks
>
> Regards
>
> Claudio Carbone
>
>
>
>
> _______________________________________________
> 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