非套接字上的套接字操作,zmq选项
Socket operation on non-socket, zmq options
每当我试图在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。
编辑:尝试在绑定之前/之后设置选项,没有任何更改。
您应该为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));
记住API v2.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兼容的代码应在进入.connect()
/.bind()
.setsockopt()
以设置ZMQ_RCVTIMEO
相关文章:
- 当套接字连接断开时检测C/C++Unix
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- 套接字读取后,我在缓冲区中看到意外输入
- 如何在CPP中创建应该在Windows和Linux上运行的套接字?
- 我可以与 python 服务器而不是 c++ 客户端建立 tcp/ip 套接字吗?
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- (Winsock) UDP 接收工作正常,但同一套接字的发送失败
- MSG_WAITALL的套接字发送得到了 22 EINVAL
- C++套接字客户端到 Python 服务器未创建连接
- 在不知道套接字的情况下关闭网络连接
- 在新计算机上,ZMQ上下文套接字创建要慢得多
- zmq 套接字可以同时在两个线程中读取和写入吗?
- Zmq 套接字在一段时间后不工作
- 在回调函数中使用zmq套接字
- 非套接字上的套接字操作,zmq选项
- 如何启动python内核并使用ZMQ套接字进行连接
- ZMQ不适用于Linux中的原始套接字,但适用于Windows。