Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between Linux's sendfile() and Oracle Solaris' sendfile()?

I have read Linux's man page and Solaris' man page.

What I found different was this requirement in Linux's man page:

The in_fd argument must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket).

Whereas the Solaris' man page explicitly states that in_fd must correspond to a regular file, but not that it must support mmap(2)-like operations.

Apart from some different errno values (Solaris' sendfile() can fail with EINTR according to the documentation, unlike Linux's), and that out_fd must refer to a socket before Linux 2.6.33, and that I would have to link with -lsendfile on Solaris (which didn't seem to be necessary, and the code compiled fine without it), are there any other differences that are not mentioned in their man pages?

like image 786
Madagascar Avatar asked Nov 01 '25 11:11

Madagascar


1 Answers

From reading both the Linux and the Solaris 11.4 man pages, both implementations of sendfile() are effectively identical, with both having the exact same ssize_t sendfile(int out_fd, int in_fd, off_t *off, size_t len); prototype and both using the same sys/sendfile.h header file. Both man pages also seem to document the same behavior in how file offsets of both the input and output files are handled, and how the value of the off_t *offset pointer affects the updating or not updating of the input file offset.

However, the Solaris implementation also provides the capability to write data directly from the memory of the calling process to the output file descriptor. Per the Solaris 11.4 sendfile() man page:

Synopsis

#include <sys/sendfile.h>

ssize_t sendfile(int out_fd, int in_fd, off_t *off, size_t len);

Description

. . .

The sendfile() function can also be used to send buffers from the calling program's memory by setting in_fd to SFV_FD_SELF and off to the address of the memory buffer.

like image 97
Andrew Henle Avatar answered Nov 03 '25 04:11

Andrew Henle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!