cpipesplicesendfilezero-copy

Zero copy in sockets


I am writing a network application that will transfer data between a pair of sockets.

Whenever some data is available in the source socket, it will transfer it to the destination socket and vice versa. But here I am looking for the most efficient way of doing this.

So far I have found two ways for doing this:

  1. Use read() and write() calls to transfer data between sockets.
  2. Use splice() and pipes to transfer socket buffers from kernel space.

In the first approach, I have to copy the data to a user-space buffer every time, and in the second one, I have to copy the data from the source socket to a pipe and then from the pipe to the destination socket. Because one of the descriptors of splice() must be a pipe. Similarly in the case of sendfile() one of its descriptors must be a file.

I would like to know if there are any other zero-copy data transfer mechanisms available to move data between sockets.


Solution

  • The solution is SOCKMAP - there is no system call cost and no user space/ kernel space copying.

    Found an article here https://blog.cloudflare.com/sockmap-tcp-splicing-of-the-future/ explains it in detail