modpro
modpro

Reputation: 25

zmq_unbind fails in C

I'm using ØMQ in C, and I noticed that when calling zmq_unbind it returns -1. My ØMQ version is 4.2.2. Here is a simple code that fails:

#include <stdio.h>
#include <stdlib.h>
#include "zmq.h"

#define SERVER_ENDPOINT "tcp://*:5555"

int main(void)
{
  void *context = zmq_ctx_new();
  void *socket = zmq_socket(context, ZMQ_REP);
  int rc = zmq_bind(socket, SERVER_ENDPOINT);
  if (rc) {
    fprintf(stderr, "Error: could not bind the socket.\n");
    exit(1);
  }

  rc = zmq_unbind(socket, SERVER_ENDPOINT);
  if (rc) {
    fprintf(stderr, "Error: could not unbind the socket.\n");
    exit(1);
  }
  rc = zmq_close(socket);
  if (rc) {
    fprintf(stderr, "Error: could not close the socket.\n");
    exit(1);
  }

  zmq_ctx_destroy(context);

  return 0;
}

Upvotes: 1

Views: 391

Answers (1)

Enrico Detoma
Enrico Detoma

Reputation: 3179

tcp://*:5555 with the wildcard is not a valid option for zmq_unbind.

As suggested here: https://github.com/zeromq/pyzmq/issues/1025

The last_endpoint socket option can be used to retrieve the actual endpoint when using wildcards

Upvotes: 2

Related Questions