【发布时间】:2013-01-16 14:02:58
【问题描述】:
我在 web 中阅读了文档关于边缘触发的 epoll 功能如下:
1. The file descriptor that represents the read side of a pipe (rfd) is registered on the epoll instance.
2. A pipe writer writes 2 kB of data on the write side of the pipe.
3. A call to epoll_wait(2) is done that will return rfd as a ready file descriptor.
4. The pipe reader reads 1 kB of data from rfd.
5. A call to epoll_wait(2) is done.
.......
.......
使用epoll作为边缘触发(EPOLLET)接口的建议方式如下: i) 使用非阻塞文件描述符 ii) 仅在 read(2) 或 write(2) 返回 EAGAIN 后调用 epoll_wait 事件。
我理解了2,但我不知道为什么要使用非阻塞文件描述符。
谁能解释为什么使用非阻塞文件描述符? 为什么在级别触发的 epoll 函数中可以使用阻塞文件描述符?
【问题讨论】:
标签: linux socket.io nonblocking epoll