I wrote a small test program to figure out how to talk to poll. I created three files testa
,testb
,testc
and wrote the string hel
An EOF condition in a regular file is still readable. In other words, your read()
won't block. Here's a nice list of how different implementations of poll()
react to EOF in different sorts of file descriptors: http://www.greenend.org.uk/rjk/tech/poll.html
Note that regular files always return POLLIN. So you need to test for EOF separately. In fact, poll on a regular file doesn't do anything for you. You'll need sockets or pipes or something to test your code.
Other notes: you probably want to check for other results in .revents
. POLLERR, POLLHUP, and POLLNVAL all signal different error conditions, and need special handling.
The local file descriptors are always ready to perform I/O (unlike sockets, because they are depend on the kernel internal buffer for I/O)). In your case file descriptors are always ready for reading, even if they are empty actually.
Once you reach the end of a file, it remains readable so that poll
will return immediately, and calling read
will immediately return zero. You need to handle this condition, perhaps by closing it and removing it from the set of polls, where you're currently printing Strange
.