zxCoder
V2EX  ›  问与答

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

  •  
  •   zxCoder · Jun 1, 2021 · 902 views
    This topic created in 1818 days ago, the information mentioned may be changed or developed.

    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 replies    2021-06-01 17:32:43 +08:00
    AoEiuV020
        1
    AoEiuV020  
       Jun 1, 2021
    系统调用忘得差不多了,按我字面上理解,他能保证一次无阻塞的 read,不能保证一次无阻塞的 write,除非 write 内容足够小,
    应该是 read 你无论传多大的 buf 进去,实际有多少内容就会读多少内容,然后直接返回真实读取的字节数不阻塞,
    而 write 不一样,参数 buf 太大的话,一次写不完的话,是会继续阻塞直到全部写完的,
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   953 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 466ea39e · 36ms · UTC 18:49 · PVG 02:49 · LAX 11:49 · JFK 14:49
    ♥ Do have faith in what you're doing.