[zeromq-dev] EAGAIN with zmq_disconnect on inproc socket

Stefan Radomski radomski at tk.informatik.tu-darmstadt.de
Mon Dec 3 16:25:44 CET 2012


Hi there,

I keep getting an EAGAIN error with ZeroMQ 3.2.2 on MacOSX 10.8.2 when calling zmq_disconnect on an inproc socket (works fine for tcp). Minimal testcase is attached. It seems the problem is in socket_base.cpp:588 as the "endpoints" multimap does not contain inproc endpoints. Which is to be expected, because zmq::socket_base_t::connect returns 0 for inproc sockets without ever adding the endpoints (socket_base.cpp:556).

I will submit a bug report shortly but would like to get a confirmation first that this is not intended behavior. In my opinion the type of endpoint should not cause the semantics of zmq_connect / zmq_disconnect to change.

Best regards
Stefan


#include <zmq.h>
#include <inttypes.h>
#include <string.h>

int main(int argc, char** argv) {
  void* context = zmq_ctx_new();
  void* pubSocket;
  void* subSocket;



  (pubSocket = zmq_socket(context, ZMQ_XPUB))         || printf("zmq_socket: %s\n", zmq_strerror(errno));
  (subSocket = zmq_socket(context, ZMQ_SUB))          || printf("zmq_socket: %s\n", zmq_strerror(errno));
  zmq_setsockopt(subSocket, ZMQ_SUBSCRIBE, "foo", 3)  && printf("zmq_setsockopt: %s\n",zmq_strerror(errno));



  zmq_bind(pubSocket, "inproc://someInProcDescriptor") && printf("zmq_bind: %s\n", zmq_strerror(errno));
  //  zmq_bind(pubSocket, "tcp://*:30010") && printf("zmq_bind: %s\n", zmq_strerror(errno));



  int32_t more;
  size_t more_size = sizeof(more);
  int iteration = 0;



  while(1) {
    zmq_pollitem_t items [] = {
      { pubSocket,    0, ZMQ_POLLIN, 0 }, // read subscriptions
    };
    zmq_poll(items, 1, 500);



    if (items[0].revents & ZMQ_POLLIN) {
      while (1) {
        zmq_msg_t msg;
        zmq_msg_init (&msg);
        zmq_msg_recv (&msg, pubSocket, 0);
        int msgSize = zmq_msg_size(&msg);
        char* buffer = (char*)zmq_msg_data(&msg);



        if (buffer[0] == 0) {
          printf("unsubscribing from %s\n", strndup(buffer + 1, msgSize - 1));
        } else {
          printf("subscribing on %s\n", strndup(buffer + 1, msgSize - 1));
        }



        zmq_getsockopt (pubSocket, ZMQ_RCVMORE, &more, &more_size);
        zmq_msg_close (&msg);



        if (!more)
          break;      //  Last message part
      }
    }



    if (iteration == 1) {
      zmq_connect(subSocket, "inproc://someInProcDescriptor") && printf("zmq_connect: %s\n", zmq_strerror(errno));
      //      zmq_connect(subSocket, "tcp://127.0.0.1:30010") && printf("zmq_connect: %s\n", zmq_strerror(errno));
    }



    if (iteration == 2) {
      zmq_disconnect(subSocket, "inproc://someInProcDescriptor") && printf("zmq_disconnect(%d): %s\n", errno, zmq_strerror(errno));
      //      zmq_disconnect(subSocket, "tcp://127.0.0.1:30010") && printf("zmq_disconnect: %s\n", zmq_strerror(errno));
    }



    if (iteration == 3) {
      break;
    }



    iteration++;
  }



  zmq_close(pubSocket) && printf("zmq_close: %s", zmq_strerror(errno));
  zmq_close(subSocket) && printf("zmq_close: %s", zmq_strerror(errno));



  zmq_ctx_destroy(context);
  return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121203/ad006751/attachment.htm>


More information about the zeromq-dev mailing list