简体   繁体   English

没有文件描述符的Sendfile

[英]Sendfile without file descriptor

I have a memory region which contains data that I would like to send over ethernet to the other client. 我有一个内存区域,其中包含我想通过以太网发送给其他客户端的数据。 To increase the throughput, currently I am fiddling with sendfile API instead of the classic send/write API. 为了提高吞吐量,当前我摆弄sendfile API而不是经典的send / write API。 But as far as I understand, the sendfile API requires a file descriptor for input, but what I have is only raw memory data. 但是据我所知,sendfile API需要输入的文件描述符,但是我只有原始内存数据。 So what should I do in order to use the sendfile API? 那我该怎么做才能使用sendfile API?

The primary benefit of sendfile() is that it allows you to avoid the overhead of having to first read() data from a file descriptor into memory before you can send() it. sendfile()的主要好处在于,它可以避免必须先将文件描述符中的数据read()入内存然后再send()的开销。 If the data you want to send is already in memory, sendfile() is not needed. 如果要发送的数据已在内存中,则不需要sendfile() Using weird workarounds to move the data into a file (like mmap() ing it) will only reduce performance. 使用怪异的解决方法将数据移动到文件中(例如mmap() )只会降低性能。

如果您运行的是Linux,则可以查看拼接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM