Socket#sendfile

Rubyforge Project:

rubyforge.org/projects/rctools/

Documentation:

dev.robotcoop.com/Libraries/socket_sendfile/

About

Socket#sendfile implements sendfile(2) for sending files without copying data to the process. See the sendfile(2) manual page for more details.

Note that your system must support the sendfile(2) system call the same way FreeBSD does for Socket#sendfile to work.

Installing socket_sendfile

First you need an OS that supports sendfile() the way FreeBSD does.

Then install the gem:

$ sudo gem install socket_sendfile

Using socket_sendfile

require 'rubygems'
require 'socket'
require 'socket_sendfile'

socket = TCPSocket.open host, port

File.open 'myfile' do |fp|
  socket.sendfile fp
end