Why does poll keep returning although there is no input?

后端 未结 3 1108
南旧
南旧 2020-12-18 07:12

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

3条回答
  •  一个人的身影
    2020-12-18 07:34

    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.

提交回复
热议问题