zmq_unbind 在 C 中失败

zmq_unbind fails in C

我在 C 中使用 ØMQ,我注意到在调用 zmq_unbind 时它 returns -1。我的 ØMQ 版本是 4.2.2。这是一个失败的简单代码:

#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;
}

tcp://*:5555 与通配符不是 zmq_unbind 的有效选项。

这里建议:https://github.com/zeromq/pyzmq/issues/1025

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