发送和接收消息的功能如下:
int zmq_send (void *socket, void *buf, size_t len, int flags);
int zmq_recv (void *socket, void *buf, size_t len, int flags);但是,从文档中可以看出,何时必须直接使用zmq_msg_t或自定义数据。那么在哪些情况下我应该考虑使用zmq_msg_t,在这种情况下直接发送数据呢?
发布于 2016-05-23 21:06:07
这两个函数都将在内部构造一个zmq_msg_t,然后使用函数的zmq_msg_t变体。这很方便,但是如果您想要多次发送相同的消息,那么创建一个zmq_msg_t并使用这些变体会更有效(减少复制)。
发布于 2016-05-23 20:58:04
永不TLDR
在如何设置、加载/卸载以及使用/销毁支持的低级别数据结构方面要相当小心,这些支持是凉爽而强大的ZeroMQ-library服务所依赖的。
否则,最好还是使用高级的伴生函数。
不要犹豫去读这本书--值得花些时间
Pieter在第42页第4项中建议:
若要发布(而不是销毁)消息,请调用
zmq_msg_close().这将删除一个引用,最终0MQ将销毁该消息。
在API文档中,您可能会发现更强烈的警告:
The zmq_msg_close() function shall inform the ØMQ infrastructure
that any resources associated with the message object
referenced by msg are no longer required and may be released.
Actual release of resources associated with the message object
shall be postponed by ØMQ until all users of the message or underlying
data buffer have indicated it is no longer required.
Applications should ensure that zmq_msg_close() is called
once a message is no longer required, otherwise memory leaks may occur.zmq_msg_t 从不直接访问成员,总是使用zmq_msg系列函数。
Return value:
zmq_msg_close() function shall return zero if successful.
Otherwise it shall return -1 and
set errno to one of the values defined below.
Errors
EFAULT Invalid message.https://stackoverflow.com/questions/37399101
复制相似问题