1 # -*- encoding: binary -*-
2 require_relative 'helper'
6 class TestSendfile < Test::Unit::TestCase
7 def test_linux_sendfile
8 rd, wr = UNIXSocket.pair
10 src = Tempfile.new('ruby_sf_src')
11 assert_equal 0, SleepyPenguin.linux_sendfile(wr, src, size)
13 assert_equal str.bytesize, src.syswrite(str)
14 assert_equal 0, SleepyPenguin.linux_sendfile(wr, src, size)
15 src.sysseek(0, IO::SEEK_SET)
16 assert_equal str.bytesize,
17 SleepyPenguin.linux_sendfile(wr, src, size, offset: 0)
18 assert_equal str, rd.read(size)
19 assert_equal 0, src.sysseek(0, IO::SEEK_CUR), 'handle offset not changed'
20 assert_equal 3, SleepyPenguin.linux_sendfile(wr, src, 3)
21 assert_equal 3, src.sysseek(0, IO::SEEK_CUR), 'handle offset changed'
23 [ rd, wr ].compact.each(&:close)