[zeromq-dev] ZMQ_XREQ - assertion failed

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


I need a simple request/response interaction, though I am not happy with ZMQ_REQ/ZMQ_REP pattern.
The main reason is it is unclear what I supposed to do if a response from a server is delayed or lost.
Do we have an example covers e.g. reopening the socket in this case? 

Is it reasonable to look into XREQ/XREQ direction to have the reliability problem addressed?

Converting the simplest REQ/REP example to XREP/XREP, I've found out it crashes with 
"Assertion failed: msg_->flags & ZMQ_MSG_MORE (xrep.cpp:146)".
To keep the ball rolling, I've added extra recv (after getsockopt with ZMQ_RCVMORE) and
extra send with ZMQ_SNDMORE at ZMQ_XREP side, so my server looks like
  // 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_XREP);


    zmq::message_t msg_req_head;

    int ret = s.recv(&msg_req_head);

    int64_t more = 0;
    size_t more_size = sizeof more;
    s.getsockopt(ZMQ_RCVMORE, &more, &more_size);

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

    if (more)
      zmq::message_t msg_req;
      int ret = s.recv(&msg_req);
      std::cout << "received (more):" <<
      std::string((const char*)msg_req.data(), msg_req.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_req_head, ZMQ_SNDMORE);
    std::cout << "sent first part" << std::endl;
The questions (besides general REQ/REQ reliability advice request) are if it is expected 0mq user have to add extra recv/send
and if it is correct to return first part of a message to sender.


More information about the zeromq-dev mailing list