It seems that writes/reads to regular files can't not be made non-blocking. I found the following references for support:

from The Linux Programming Interface: A Linux and UNIX System Programming Handbook:

from Advanced Programming in the UNIX Environment 2nd Ed:

from http://www.remlab.net/op/nonblock.shtml:

When memory is adequately available, reads/writes is performed through kernel buffering.

简单来说,对于普通的磁盘文件来说,可读可写条件总是成立的(不像socket缓冲区空了就没法读,缓冲区满了就没法写),所以设置非阻塞模式并没有意义。

问题在于,虽然系统并不认为读/写普通文件会阻塞,可是实际上由于磁盘可能比较繁忙或者比较慢等因素,导致读/写事件延迟很长,同样带来阻塞的问题,

但这种问题却根本无法避免!

04-14 03:42