I am trying to use zmq_poll on stdin, but find that if something comes in on
stdin, the poll returns with a 1, but the .revents field is zero. See code
below.
Any subsequent calls to zmq_poll, immediately return with a 1, but .revents
field remains 0.
Am I setting up the zmq_pollitem_t properly.
Thanks,
Benjy
int main (void)
{
void *context = zmq_ctx_new ();
int rc;
string request;
while (1)
{
zmq_pollitem_t items [1];
items[0].socket = NULL;
items[0].fd = STDIN_FILENO;
items[0].events = ZMQ_POLLIN;
/* Poll for events indefinitely */
rc = zmq_poll (items, 1, -1);
if (rc < 0)
{
perror("zmq_poll error: ");
return 0;
}
else if (rc ==0)
{
cout << "timeout" << endl;
}
else
{
//cout << rc << endl;
//cout << "items[0].socket: "
<< items[0].socket << " items[0].fd: " <<items[0].fd << " items[0].events: "
<< items[0].events << " items[0].revents: " <<items[0].revents << endl;
//cout << "items[1].socket: "
<< items[1].socket << " items[1].fd: " <<items[1].fd << " items[1].events: "
<< items[1].events << " items[1].revents: " <<items[1].revents << endl;
}
if (items[0].revents & ZMQ_POLLIN)
{
// Got a request from cli
getline(cin, request);
cout << request << endl;
}
}
zmq_ctx_destroy (context);
return 0;
}
________________________________
- CONFIDENTIAL-
This email and any files transmitted with it are confidential, and may also be
legally privileged. If you are not the intended recipient, you may not review,
use, copy, or distribute this message. If you receive this email in error,
please notify the sender immediately by reply email and then delete this email.
________________________________
- CONFIDENTIAL-
This email and any files transmitted with it are confidential, and may also be
legally privileged. If you are not the intended recipient, you may not review,
use, copy, or distribute this message. If you receive this email in error,
please notify the sender immediately by reply email and then delete this email.
_______________________________________________
zeromq-dev mailing list
[email protected]
https://lists.zeromq.org/mailman/listinfo/zeromq-dev