I have a socket I\'m doing select()
on it, waiting for other process to write.
Once it write, I read the data, and write it to another file descriptor.
My question
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