zxCoder
V2EX  ›  问与答

c 语言 select 函数的文档里的这句话怎么理解

By zxCoder at 2021 年 6 月 1 日 · 1164 次点击

A file descriptor is considered ready if it is possible to perform a corresponding I/O operation (e.g., read(2), or a sufficiently small write(2)) without blocking.

为什么是 read 和 a sufficiently small write 呢?

1 条回复  •  2021-06-01 17:32:43 +08:00
AoEiuV020
   1
AoEiuV020  
   2021 年 6 月 1 日
系统调用忘得差不多了,按我字面上理解,他能保证一次无阻塞的 read,不能保证一次无阻塞的 write,除非 write 内容足够小,
应该是 read 你无论传多大的 buf 进去,实际有多少内容就会读多少内容,然后直接返回真实读取的字节数不阻塞,
而 write 不一样,参数 buf 太大的话,一次写不完的话,是会继续阻塞直到全部写完的,
© 2026 V2EX · 33ms · 3.9.8.5