【发布时间】:2019-09-07 21:52:28
【问题描述】:
我在 C 中使用 ØMQ,我注意到在调用 zmq_unbind 时它返回 -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;
}
【问题讨论】:
-
你能检查一下errno吗?
-
@EnricoDetoma
printf("%d - %s\n", rc, zmq_strerror(errno));返回“-1 - 没有这样的文件或目录”。