每当我尝试在zmq中设置套接字选项时,我都会Socket operation on non-socket
。
zmq::socket_t socket = new zmq::socket_t(*context,ZMQ_REP);
int64_t t = 1000;
socket->setsockopt(ZMQ_RCVTIMEO,&t,sizeof(t));
socket->bind("ipc:///tmp/zmqsocket");
有人能告诉我我做错了什么吗?
我正在使用带有c ++绑定的ZeroMQ 4.0.4。
编辑:尝试在绑定之前/之后设置选项,没有任何更改。
答案 0 :(得分:4)
您应该为ZMQ_RCVTIMEO选项使用正确的类型,它使用int(不是int64)。
来自zmq文档zmq-setsockopt
ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN
Sets the timeout for receive operation on the socket. If the value is 0, zmq_recv(3) will return immediately, with a EAGAIN error if there is no message to receive. If the value is -1, it will block until a message is available. For all other values, it will wait for a message for that amount of time before returning with an EAGAIN error.
Option value type int
Option value unit milliseconds
Default value -1 (infinite)
Applicable socket types all
然后以下代码正在运行:
zmq::context_t context(1);
zmq::socket_t socket(context,ZMQ_REP);
int t = 1000;
socket.bind("ipc:///tmp/zmqsocket");
socket.setsockopt(ZMQ_RCVTIMEO,&t,sizeof(t));
答案 1 :(得分:1)
就在v2.1中, setsockopt()
联机帮助警告表示:
int zmq_setsockopt ( void *socket,
int option_name,
const void *option_value,
size_t option_len
);
Caution: All options,
with the exception of ZMQ_SUBSCRIBE, ZMQ_UNSUBSCRIBE,
ZMQ_LINGER, ZMQ_ROUTER_MANDATORY,
ZMQ_PROBE_ROUTER, ZMQ_XPUB_VERBOSE,
ZMQ_REQ_CORRELATE,
and ZMQ_REQ_RELAXED,
only take effect for subsequent socket bind/connects.
^^^^ ^^^^^^^^^^
希望与已发布的ZeroMQ API兼容的代码应调用.setsockopt()
将 ZMQ_RCVTIMEO 设置为 前往.connect()
/ { {1}}