poll() function
poll() function
- Subject: poll() function
- From: Ilfak Guilfanov <email@hidden>
- Date: Mon, 31 Jul 2006 14:26:48 +0200
- Organization: Datarescue sa/nv
Hi,
I'm trying to read characters from the terminal while doing other
things. The following simple program checks if a character is
ready from the keyboard. For some reason it doesn't work.
------------
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <poll.h>
int main()
{
struct pollfd pfd;
pfd.fd = STDIN_FILENO;
pfd.events = POLLIN;
int code = poll(&pfd, 1, 200);
printf("code=%d pfd.fd=%d pfd.revents=%d\n", code, pfd.fd, pfd.revents);
if ( pfd.revents & POLLNVAL )
abort();
}
-----------
It aborts because the poll() function returns the POLLNVAL bit which
means that the file descriptor is invalid. The file descriptor is
STDIN_FILENO which is a perfectly valid descriptor. If I replace it
with another descriptor, the program does not abort anymore, but it
doesn't work with stdin...
Could anyone enlightened in MAC OS X programming clarify why it behaves so?
I do not see any programming errors in it.
P.S. I'm sorry if this is not the right mailing list for this question...
--
Best regards,
Ilfak mailto:email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden