[zeromq-dev] zmq_poll: timeout issue

ilejncs ilejncs at narod.ru
Tue Aug 10 15:31:55 CEST 2010


Hello!

I am observing rather strange zmq_poll behavior.
It is triggered by timeout and works fine if  -1.

The client looks like
==
    zmq::context_t ctx (1);

    zmq::socket_t s(ctx, ZMQ_REQ);

    //  Connect to the server.
    s.connect ("tcp://localhost:23001");

    for (int i = 0; i != 20; i++)
    {
        zmq::message_t request (10);
        strcpy((char*)request.data (), "AAAAAAAAA");
        s.send (request);
        
        zmq_pollitem_t items[1];
        items[0].socket = s;
        items[0].events = ZMQ_POLLIN;

        int poll_ret = zmq::poll(items, 1, 1000000);
        if (items[0].revents == ZMQ_POLLIN)
        {
          assert(poll_ret > 0);
          
          //  Get the reply. 
          zmq::message_t reply;
          s.recv(&reply);
          std::cout << (char*)reply.data() << std::endl;
        }
        else
        {
          std::cout << "reconnecting," <<
            "poll_ret=" << poll_ret << std::endl;
        }
    }
==

the server is even more simpler and replies with a constant string.
==
  // Initialise 0MQ context with one I/O thread
  zmq::context_t ctx (1);

  // Create a ZMQ_REP socket to recieve requests and send replies
  zmq::socket_t s (ctx, ZMQ_REP/*ZMQ_XREP*/);

  s.bind("tcp://*:23001");

  for(;;)
  {
    zmq::message_t msg_req_head;
    int ret = s.recv(&msg_req_head);

    std::cout << "received:" <<
      std::string((const char*)msg_req_head.data(), msg_req_head.size()) <<
      ", ret=" << ret << std::endl;

    char* response_area = (char*) malloc(100);
    strcpy(response_area, "this is a response");
  
    zmq::message_t msg_rep(response_area, strlen(response_area) + 1, my_free);

    s.send(msg_rep);
  }
==

The issue is _sometimes_ the client goes to "reconnecting" branch while server is up and running.

Linux 2.6.18, x86_64.
0mq - 2.0.7

Could someone please look into this and check if timeout in zmq_poll is Ok.

Thanks.

--
Best regards,
Ilja Golshtein.




More information about the zeromq-dev mailing list