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

erupter at libero.it erupter at libero.it
Thu Aug 16 18:49:48 CEST 2012

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);
        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");
        // 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?
ThanksRegardsClaudio Carbone

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

More information about the zeromq-dev mailing list