【问题标题】:sendfile() doesn't work to copy normal text filesendfile() 无法复制普通文本文件
【发布时间】:2011-07-21 01:37:42
【问题描述】:

sendfile 的问题是它不能使用文件 fds 复制两个文本文件。 错误是 EINVAL。 // 描述符无效或被锁定,或类似 mmap() 的操作不适用于 in_fd。

这到底是什么意思?

从 sendfile ( man sendfile ) 的手册页中,我找到了这个语句。不确定是否可以复制两个常规文件。

目前(Linux 2.6.9):in_fd,必须对应于支持类似 mmap() 操作的文件(即,它不能是套接字);和 out_fd 必须引用一个套接字。

   Applications may wish to fall back to read(2)/write(2) in the case where sendfile() fails with EINVAL or ENOSYS.

【问题讨论】:

    标签: text file sendfile


    【解决方案1】:

    sendfile() 背后的想法是通过套接字快速发送文件(想想 Web 服务器)。常规文件可以是mmap()ed,但不是套接字,因此当您将常规文件作为目标时它会爆炸。

    【讨论】:

    • 手册页如果 sendfile 也建议相同。现在我正在使用标准。 c++方式。 ofstream
    • 并非如此。操作系统通常不会提供“在此处复制此文件”系统调用。
    猜你喜欢
    • 2012-12-12
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 2016-05-23
    相关资源
    最近更新 更多