I want to write a gRPC server(c++) which serves as a FTP server in some case. In detail, client requests a file by its name, while server returns the file content if it exists. In traditional socket programming, I can implement zero-copy utilizing sendfile
for linux system. It means that the file content would go directly to socket buffer from disk without transferred in user space. But in gRPC world, the socket detail is hidden, which means you might not access the file descriptor behind the socket that is necessary for sendfile
:
ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
Therefore, I must read the file bytes into memory first and return it in gRPC response afterwards. That's an unnecessary performance loss. I'm wondering if there's any APIs or workaround for it.