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.
Doing a
sendfilestraight over a low-level grpc socket wouldn't make a lot of sense, as the grpc protocol will itself have a lot of framing around the data being sent. Your data will be naturally chunked and potentially multiplexed with other control data. Therefore, there is no API to do what you want.