【问题标题】:Why does sendfile not check if reading from the input descriptor would block?为什么 sendfile 不检查从输入描述符读取是否会阻塞?
【发布时间】:2018-05-15 21:17:58
【问题描述】:

作为服务器,我想从非阻塞客户端套接字读取,然后写入文件。

根据 sendfile 的手册页,如果 errno 设置为 EAGAIN,那么这仅表明,如果 output 文件描述符设置为非阻塞,则调用 sendfile 将块。

也就是说,sendfile 对 write 进行的底层调用会阻塞。

如果读取会阻塞,是否仍然可以使用 sendfile 以使 errno 成为 EAGAIN?

【问题讨论】:

    标签: c server errno sendfile


    【解决方案1】:

    当然。

    将select() 库函数与您的读取描述符一起使用,您可以通过errno 检查EWOULDBLOCK。如果已设置,则读取将阻塞。

    您无法通过检查sendfile() 调用中的某些内容来查看读取是否会阻塞。

    【讨论】:

      猜你喜欢
      • 2011-08-02
      • 1970-01-01
      • 2019-02-06
      • 2011-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      相关资源
      最近更新 更多