- 论坛徽章:
- 0
|
原帖由 cugb_cat 于 2008-4-29 20:15 发表 ![]()
在使用非阻塞模式时,ET模式下要一直循环直到EAGAIN错误。
还有楼主说的那个相应的buffer,就是内核缓冲区,这个缓冲区与文件IO中文件系统中的缓冲区概念是差不多的。
前一句话我的理解与你不同,我的理解是:
在ET模式下,不需要循环读到EAGAIN.只要你read返回的数据小于你请求的数据时,则认为已读尽缓冲区了.
请看这个:
Q9 Do I need to continuously read/write an fd until EAGAIN when using the EPOLLET flag ( Edge Triggered
behaviour ) ?
A9 No you don't. Receiving an event from epoll_wait(2) should suggest to you that such file descriptor is
ready for the requested I/O operation. You have simply to consider it ready until you will receive the
next EAGAIN. When and how you will use such file descriptor is entirely up to you. Also, the condition
that the read/write I/O space is exhausted can be detected by checking the amount of data read/write
from/to the target file descriptor. For example, if you call read(2) by asking to read a certain amount
of data and read(2) returns a lower number of bytes, you can be sure to have exhausted the read I/O
space for such file descriptor. Same is valid when writing using the write(2) function. |
|