Further Information

Source and Usage

You can download the full source code from ftp.ssc.com/pub/lj/listings/issue105/6345.tgz. Type tar -zxvf sfl-src.tgz to unpack it and make to build the executable. You should have an executable file called sfl in your directory; if you start it without any parameters, it will display usage. You have to specify the server's IP address in both server and client instances of the sfl command. Here is a use case:


[email protected]:~/sfl-src > ./sfl s
Server binding to []
Server sent 10240 bytes.
[email protected]:~/sfl-src >


[email protected]:~/sfl-src > ./sfl r
Client connecting to []
Client received 10240 bytes.
[email protected]:~/sfl-src >

Code Comments

1. I used port 1033; use a different port if there is a conflict on your system.

2. To make the example code shorter and simpler, I put the 10K buffer on the stack. You should use malloc to allocate buffers in your code.

3. To make the code shorter for the article, I skipped checking the return value of the close system call. In a real-world program you should definitely check the return value.


If you are interested in learning more about the usage of the sendfile system call, take a look at some of the applications that use it: Apache (www.apache.org), Samba (www.samba.org), Mozilla (www.mozilla.org) and Pure-FTPd (pureftpd.sf.net).

To learn more about kernel file leases, take a look at Samba code, in the file smbd/oplock_linux.c.