您的位置首页生活百科

为什么 IO 多路复用要搭配非阻塞 IO?

为什么 IO 多路复用要搭配非阻塞 IO?

的有关信息介绍如下:

为什么 IO 多路复用要搭配非阻塞 IO?

man 2 select 「BUGS」节:

Under Linux, select() may report a socket file descriptor as "ready for reading", while nevertheless a subsequent read blocks. This could for example happen when

data has arrived but upon examination has wrong checksum and is discarded. There may be other circumstances in which a file descriptor is spuriously reported as

ready. Thus it may be safer to use O_NONBLOCK on sockets that should not block.

就算数据不会被别人读走,也可能被内核丢弃。还有文档没有明说的其它情况。