# \[ANN\] ruby-sendfile 0.9.1

**URL:** <https://www.ruby-forum.com/t/ann-ruby-sendfile-0-9-1/87329>\
**Category:** Ruby\
**Created:** [March 26, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/ann-ruby-sendfile-0-9-1/87329 "2006-03-26T18:59:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 26, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/ann-ruby-sendfile-0-9-1/87329/1 "2006-03-26T18:59:41Z")

</div>

As promised, I’ve updated ruby-sendfile to make it more “1.0”. There is  
a source tarball and gem up on Rubyforge, whichever you prefer. I’ve  
also added unit tests to make sure that full and partial sends work on  
both blocking and non-blocking sockets on all supported OSs (everything  
that has a recognizable sendfile(2)). Unlike socket\_sendfile,  
ruby-sendfile can send a partial file with the optional offset and byte  
count parameters (see below).

All tests pass on Linux (tested on x86 and AMD64, both 2.6.x) and  
FreeBSD (tested on 5.3-RELEASE), and ruby-sendfile will truly be 1.0  
when the tests pass on Solaris. They should pass right now, but I don’t  
have a box to test them on.

P.S. Eric: now _these_ are tests 😉

[Changelog]

- Improved interface with non-blocking sockets
- Added unit tests for blocking sends
- Added unit tests for nonblocking sends
- Added README
- Packaged in a RubyGem

[README]

= Ruby sendfile(2) Interface

This module allows Ruby programs to access their OS’s native  
sendfile(2) system call from any IO object. Your kernel must  
export a recognized signature for the sendfile(2) system call  
to use this module. Currently, that includes Linux, Solaris  
and FreeBSD.

== Installation

Download and install the latest package from the [rubyforge.org](http://rubyforge.org)  
RubyGems repository.

gem install sendfile --remote  
gem check sendfile --test

If the tests all pass, you’re ready to start using sendfile.

Or, if you don’t have rubygems installed, you can install by  
hand by downloading the tarball:

tar xzvf ruby-sendfile-.tar.gz  
cd ruby-sendfile-/ext  
ruby extconf.rb  
make  
sudo make install

== Usage

Here’s a small example of a use of IO#sendfile.

require ‘socket’  
require ‘rubygems’  
require ‘sendfile’

s = TCPSocket.new ‘[yourdomain.com](http://yourdomain.com)’, 5000  
File.open ‘somefile.txt’ { |f| s.sendfile f }  
s.close

See the test scripts for more examples on how to use this  
module.

== Contact Information

This project’s homepage is:

[http://rubyforge.org/projects/ruby-sendfile](http://rubyforge.org/projects/ruby-sendfile)

Thereupon are forums for discussing issues  
can be found for working out any issues you may have with this  
module. In the last case, you can email questions or patches  
to removed\_email\_address@domain.invalid.

–  
Toby DiPasquale

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 26, 2006, 7:06pm UTC](https://www.ruby-forum.com/t/ann-ruby-sendfile-0-9-1/87329/2 "2006-03-26T19:06:29Z")

</div>

On Mon, 27 Mar 2006, Toby DiPasquale wrote:

> when the tests pass on Solaris. They should pass right now, but I don’t  
> have a box to test them on.

i can test on solaris… but not till monday. thanks alot for this  
work!

-a

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 27, 2006, 6:26am UTC](https://www.ruby-forum.com/t/ann-ruby-sendfile-0-9-1/87329/3 "2006-03-27T06:26:34Z")

</div>

Toby,

You are calling a “rv\_sys\_fail” function in sendfile.c instead of  
rb\_sys\_fail. Otherwise seems to work great. I’ll be adding this as a  
dynamic require for Mongrel so if folks have it installed it will be  
used in  
the DirHandler.

Zed A. Shaw

> **[Zed A. shaw](https://zedshaw.com/)**
>
> Personal essays and writings by Zed A. Shaw.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 16, 2010, 12:39pm UTC](https://www.ruby-forum.com/t/ann-ruby-sendfile-0-9-1/87329/4 "2010-09-16T12:39:34Z")

</div>

Zed S. wrote:

> Toby,
> 
> You are calling a “rv\_sys\_fail” function in sendfile.c instead of  
> rb\_sys\_fail. Otherwise seems to work great. I’ll be adding this as a  
> dynamic require for Mongrel so if folks have it installed it will be  
> used in  
> the DirHandler.
> 
> Zed A. Shaw  
> [http://www.zedshaw.com/](http://www.zedshaw.com/)

will it be useful for large file download ???

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 16, 2010, 4:15pm UTC](https://www.ruby-forum.com/t/ann-ruby-sendfile-0-9-1/87329/5 "2010-09-16T16:15:03Z")

</div>

Amit T. wrote:

> will it be useful for large file download ???

You are re-opening a four-and-a-half year old thread ???

If you want to know what sendfile does, have a look at the sendfile(2)  
manpage. Basically, it allows a process to tell the kernel to copy data  
between two open file descriptors (like a file and a socket), without  
having to slurp the data from kernel into userland and back into kernel  
again.
