简体   繁体   English

关于 ZeroMQ 和非阻塞套接字轮询:

[英]About ZeroMQ and polling on non-blocking sockets :

In Linux, if an application uses raw non-blocking sockets for reading, in conjunction with poll, will it be possible to be notified when a socket has some data available for reading or not?在 Linux 中,如果应用程序使用原始非阻塞套接字进行读取,结合轮询,是否可以在套接字有一些数据可供读取时得到通知?

I tried to dig into ZeroMQ documentation, but I cannot find my way.我试图深入研究 ZeroMQ 文档,但我找不到我的方法。

I found the flag ZMQ_NOBLOCK , but it is applied when called zmq_recv .我找到了标志ZMQ_NOBLOCK ,但它在调用zmq_recv时被zmq_recv

Is there a way to set the socket itself as Non-Blocking so that poll can return immediately if there is nothing to read?有没有办法将套接字本身设置为非阻塞,以便在没有任何内容时轮询可以立即返回?

I am using C++ as language for my app.我使用 C++ 作为我的应用程序的语言。

Well, there are few missed points here:好吧,这里有几个遗漏点:

First, a ZeroMQ- Socket -instance is not anything like an O/S socket.首先,ZeroMQ- Socket实例与 O/S 套接字完全不同。 For principal disambiguation, feel free to read posts on conceptual differences.对于主要消歧,请随时阅读有关概念差异的帖子。

This is an often re-articulated misconception, so let me repeat it in bold.这是一个经常被重新阐明的误解,所以让我用粗体重复一遍。

Beware: ZeroMQ Socket() -instance is not a tcp-socket-as-you-know-it.注意: ZeroMQ Socket() -instance不是tcp-socket-as-you-know-it。 Best read about the main conceptual differences in [ ZeroMQ hierarchy in less than a five seconds ] or other posts and discussions here关于[主要概念分歧最好看的ZeroMQ层次不到5秒]或其他职位,并在这里讨论


The ZMQ_NOBLOCK symbol can be used in more places: ZMQ_NOBLOCK符号可以用在更多地方:

the zmq_recv() being one such, zmq_send() being another. zmq_recv()是一个, zmq_send()是另一个。

This symbol is principaly #define -ed in header file, but somewhere having also some other value-identical aliases, a zmq.DONTWAIT being one such flag -composition related symbol for python-wrappers/bindings.这个符号在头文件中主要是#define -ed,但在某处也有一些其他值相同的别名,一个zmq.DONTWAIT是 python-wrappers/bindings 的一个这样的flag相关符号。


The Socket -instance has no such property as (not-)being blocking: Socket实例没有 (not-) 阻塞这样的属性:

this is the core principal miss in your so far posted questions.这是您迄今为止发布的问题中的核心主要失误。

The Socket -instance does not persist any such feature per-se. Socket实例本身不保留任何此类功能。

The respective ( individual ) instance operation - a call to a { .recv() | .send() }相应的(单独的)实例操作 - 调用{ .recv() | .send() } { .recv() | .send() } -method can use a parameter-based mechanism to change it's per-call modus operandi: { .recv() | .send() } -method 可以使用基于参数的机制来更改其每次调用的操作方式:
flags = { 0, ZMQ_DONTWAIT, ZMQ_SENDMORE, ZMQ_DONTWAIT && ZMQ_SENDMORE } but having no such option to "turn"-any-such mode on/off to persist. flags = { 0, ZMQ_DONTWAIT, ZMQ_SENDMORE, ZMQ_DONTWAIT && ZMQ_SENDMORE }但没有这样的选项来“打开”/关闭任何此类模式以保持flags = { 0, ZMQ_DONTWAIT, ZMQ_SENDMORE, ZMQ_DONTWAIT && ZMQ_SENDMORE }


Q: " Is there a way to set the socket itself as Non-Blocking "?问:“有没有办法将套接字本身设置为非阻塞”?
A: No.答:没有。


Q: " Is there a way to set the Poller.poll() to return immediately "?问:“有没有办法设置Poller.poll()立即返回”?
A: YES!答:是的!

int zmq_poll ( zmq_pollitem_t *items, int nitems, long timeout ); int zmq_poll ( zmq_pollitem_t *items, int nitems, long timeout );

so,所以,
unless one calls zmq_poll( ..., -1 ) , which turns the polling hang indefinitely long, the zmq_poll() -call returns as late as timeout [ms] , so using timeout == 0 , the zmq_poll() -call returns immediately, whether there has been found any item or not, that's great , isn't it?除非调用zmq_poll( ..., -1 ) ,这会使轮询无限期挂起, zmq_poll()调用最晚返回timeout [ms] ,因此使用timeout == 0zmq_poll()调用返回马上,不管有没有发现任何物品,那太好了,不是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM