bridging between two file descriptors

若如初见. 提交于 2019-12-03 12:04:13
thuovila

On linux, using splice() might be more suitable, when the direction is from socket to file. Using splice() is a bit more complicated, but you get both directions. Also, I think sendfile uses splice internally these days.

There are many questions on SO already discussing the differences between splice() and sendfile(). Searching the web also reveals conflicting statements on what (sources and destinations) splice works for. The best way to know if it is suitable for your case, is to test it.

SO about compatible filesystems: Which file systems support splicing via Linux's splice(2)?

SO about old kernels not supporting splice for TCP sockets: Does Linux's splice(2) work when splicing from a TCP socket?

Splice explained: http://kerneltrap.org/node/6505

Splice source: http://lxr.linux.no/#linux+v3.8.2/fs/splice.c

Sorry if I misunderstood your situation, but do you mean something like sendfile?

sendfile - transfer data between file descriptors

#include <sys/sendfile.h>
ssize_t sendfile(int out_fd, int in_fd, off_t * offset ", size_t" " count" );

sendfile() copies data between one file descriptor and another. Because this copying is done within the kernel, sendfile() is more efficient than the combination of read(2) and write(2), which would require transferring data to and from user space.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!