io_splice 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ # -*- encoding: binary -*-
2
+ require 'test/unit'
3
+ require 'tempfile'
4
+ require 'io/splice'
5
+
6
+ class Test_IO_Splice < Test::Unit::TestCase
7
+
8
+ def test_splice
9
+ str = 'abcde'
10
+ size = 5
11
+ rd, wr = IO.pipe
12
+ tmp = Tempfile.new(nil)
13
+
14
+ assert_nothing_raised {
15
+ tmp.syswrite(str)
16
+ tmp.sysseek(0)
17
+ }
18
+
19
+ nr = IO.splice(tmp.fileno, nil, wr.fileno, nil, size, 0)
20
+ assert_equal size, nr
21
+ assert_equal str, rd.sysread(size)
22
+ end
23
+
24
+ def test_splice_in_offset
25
+ str = 'abcde'
26
+ off = 3
27
+ len = 2
28
+ rd, wr = IO.pipe
29
+ tmp = Tempfile.new(nil)
30
+
31
+ assert_nothing_raised {
32
+ tmp.syswrite(str)
33
+ tmp.sysseek(0)
34
+ }
35
+
36
+ nr = IO.splice(tmp.fileno, off, wr.fileno, nil, len, 0)
37
+ assert_equal len, nr
38
+ assert_equal 'de', rd.sysread(len)
39
+ end
40
+
41
+ def test_splice_out_offset
42
+ str = 'abcde'
43
+ rd, wr = IO.pipe
44
+ tmp = Tempfile.new(nil)
45
+
46
+ assert_nothing_raised { wr.syswrite(str) }
47
+ nr = IO.splice(rd.fileno, nil, tmp.fileno, 3, str.size, 0)
48
+ assert_equal 5, nr
49
+ assert_nothing_raised { tmp.sysseek(0) }
50
+ assert_equal "\0\0\0abcde", tmp.sysread(9)
51
+ end
52
+
53
+ def test_splice_nonblock
54
+ rd, wr = IO.pipe
55
+ tmp = Tempfile.new(nil)
56
+
57
+ assert_raises(Errno::EAGAIN) {
58
+ IO.splice(rd.fileno, nil, tmp.fileno, 0, 5, IO::Splice::F_NONBLOCK)
59
+ }
60
+ end
61
+
62
+ def test_splice_eof
63
+ rd, wr = IO.pipe
64
+ tmp = Tempfile.new(nil)
65
+ wr.syswrite 'abc'
66
+ wr.close
67
+
68
+ nr = IO.splice(rd.fileno, nil, tmp.fileno, 0, 5, IO::Splice::F_NONBLOCK)
69
+ assert_equal 3, nr
70
+ assert_raises(EOFError) {
71
+ IO.splice(rd.fileno, nil, tmp.fileno, 0, 5, IO::Splice::F_NONBLOCK)
72
+ }
73
+ end
74
+
75
+ def test_tee
76
+ str = 'abcde'
77
+ size = 5
78
+ rda, wra = IO.pipe
79
+ rdb, wrb = IO.pipe
80
+
81
+ assert_nothing_raised { wra.syswrite(str) }
82
+ nr = IO.tee(rda.fileno, wrb.fileno, size, 0)
83
+ assert_equal 5, nr
84
+ assert_equal str, rdb.sysread(5)
85
+ assert_equal str, rda.sysread(5)
86
+ end
87
+
88
+ def test_tee_eof
89
+ rda, wra = IO.pipe
90
+ rdb, wrb = IO.pipe
91
+ wra.close
92
+ assert_raises(EOFError) { IO.tee(rda.fileno, wrb.fileno, 4096, 0) }
93
+ end
94
+
95
+ def test_tee_nonblock
96
+ rda, wra = IO.pipe
97
+ rdb, wrb = IO.pipe
98
+ assert_raises(Errno::EAGAIN) {
99
+ IO.tee(rda.fileno, wrb.fileno, 4096, IO::Splice::F_NONBLOCK)
100
+ }
101
+ end
102
+
103
+ def test_vmsplice_array
104
+ data = %w(hello world how are you today)
105
+ r, w = IO.pipe
106
+ n = IO.vmsplice(w.fileno, data, 0)
107
+ assert_equal data.join('').size, n
108
+ assert_equal data.join(''), r.readpartial(16384)
109
+ end
110
+
111
+ def test_vmsplice_nonblock
112
+ data = %w(hello world how are you today)
113
+ r, w = IO.pipe
114
+ w.syswrite('.' * IO::Splice::PIPE_CAPA)
115
+ assert_raises(Errno::EAGAIN) {
116
+ IO.vmsplice(w.fileno, data, IO::Splice::F_NONBLOCK)
117
+ }
118
+ end
119
+
120
+ def test_constants
121
+ assert IO::Splice::PIPE_BUF > 0
122
+ %w(move nonblock more gift).each { |x|
123
+ assert Integer === IO::Splice.const_get("F_#{x.upcase}")
124
+ }
125
+ assert IO::Splice::PIPE_CAPA >= IO::Splice::PIPE_BUF
126
+ end
127
+
128
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: io_splice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - io_splice hackers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-15 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |-
17
+ The splice family of Linux system calls can transfer data between file
18
+ descriptors without the need to copy data into userspace. Instead of a
19
+ userspace buffer, they rely on an ordinary Unix pipe as a kernel-level
20
+ buffer.
21
+ email: ruby.io.splice@librelist.com
22
+ executables: []
23
+
24
+ extensions:
25
+ - ext/io_splice/extconf.rb
26
+ extra_rdoc_files:
27
+ - README
28
+ - LICENSE
29
+ - NEWS
30
+ - ChangeLog
31
+ - lib/io/splice.rb
32
+ - ext/io_splice/io_splice_ext.c
33
+ files:
34
+ - .document
35
+ - .gitignore
36
+ - .manifest
37
+ - COPYING
38
+ - ChangeLog
39
+ - GIT-VERSION-FILE
40
+ - GIT-VERSION-GEN
41
+ - GNUmakefile
42
+ - LICENSE
43
+ - NEWS
44
+ - README
45
+ - Rakefile
46
+ - examples/splice-cp.rb
47
+ - examples/splice-tee.rb
48
+ - ext/io_splice/extconf.rb
49
+ - ext/io_splice/io_splice_ext.c
50
+ - io_splice.gemspec
51
+ - lib/io/splice.rb
52
+ - local.mk.sample
53
+ - setup.rb
54
+ - test/test_io_splice.rb
55
+ has_rdoc: true
56
+ homepage: http://bogomips.org/ruby_io_splice/
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - -Na
62
+ - -t
63
+ - io_splice - zero-copy pipe I/O for Linux and Ruby
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project: qrp
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: zero-copy pipe I/O for Linux and Ruby
85
+ test_files:
86
+ - test/test_io_splice.rb