kqueue() and O_NONBLOCK

2019-05-22 18:21发布

If you use kqueue(), should you set O_NONBLOCK on your file descriptors? In other words, does kqueue() guarantee that the next I/O operation on a ready file descriptor will not block, regardless of whether O_NONBLOCK is set?

标签: io kqueue
2条回答
祖国的老花朵
2楼-- · 2019-05-22 18:58

If you use kqueue(), should you set O_NONBLOCK on your file descriptors?

Nope.

In other words, does kqueue() guarantee that the next I/O operation on a ready file descriptor will not block, regardless of whether O_NONBLOCK is set?

Yep.

查看更多
beautiful°
3楼-- · 2019-05-22 19:14

You do not need to. However, I generally do as a sanity check. This makes operations like read() return -1 and set errno to EWOULDBLOCK. I would much rather get an EWOULDBLOCK and know that my implementation of kqueue is buggy than have read() calls block (and therefore my program freeze) for unknown reasons.

查看更多
登录 后发表回答