I am using a call to zmq_poll
on Linux, in my C++ app, to poll from reading from console input. Right now I am not using any ZeroMQ sockets but I will in the next future.
As per my understanding zmq_poll
ONLY on Linux can use linux file descriptor including STDIN_FILENO
.
I was expecting the code below to return an EINTR
when I send a CTRL-C to my application.
When I debug it, I can see that it keeps on waiting until end of timeout and it returns res_num=0
.
zmq_pollitem_t* mpPollItems = new zmq_pollitem_t[1];
std::memset(mpPollItems,0,sizeof(zmq_pollitem_t));
mpPollItems[0].socket = NULL;
mpPollItems[0].fd = STDIN_FILENO;
mpPollItems[0].events = ZMQ_POLLIN;
// Poll for events some milliseconds
int res_num = zmq_poll (mpPollItems, 1, 10000);
zmq_poll
is using a linux 'poll' behind the scenes.
Am I doing something wrong with this code or did I misunderstand something in the way zmq_poll
works?
Could it be something to do with signal masking?
Note: I am calling zmq_poll in a separate thread I spawn from the main. I did the test using directly 'poll' and I get the same result. I can only see the signal delivered only if 'poll' is called in the main thread; if it is called on a separate thread there is no reaction.
The more recent ZeroMQ API extensions have brought a few "dirty" tricks, going outside of the original Zen-of-ZERO.
Yes, the extended use of O/S-native TCP-peers under a ZMQ_STREAM
Scalable Formal Communication Pattern archetype, became possible, but these steps start to have problems of inconsistent expectation-v/s-reality delivered.
The native O/S-file-descriptor may get imperatively injected into the .fd
item of the zmq_pollitems_t
struct
(s), yet the EINTR
signal get raised for ZeroMQ-Socket()
-instances upon propagated O/S-signals, which does not seem to work the same way for "injected"-only polling.
If the same difference persists also the "complete"-setup ( using a fully configured and setup ZMQ_STREAM
-Socket()
-instance, not a just ad-hoc, .fd
-"injected"-only trick ) polling, best raise a change-request for the package maintainers, so as to refactor the handling back to the Zen-of-Zero uniform mode for both types of polled-devices.