writev 1.0.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,8 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = 'minitest/autorun'
7
+ at.find_directories = ARGV unless ARGV.empty?
8
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2011-08-19
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,10 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bench.rb
7
+ ext/writev/extconf.rb
8
+ ext/writev/writev.c
9
+ lib/writev.rb
10
+ test/test_writev.rb
@@ -0,0 +1,52 @@
1
+ = writev
2
+
3
+ * http://github.com/tenderlove/writev
4
+
5
+ == DESCRIPTION:
6
+
7
+ This gem adds the `writev` method to IO. It provides access to the `writev`
8
+ system call on your IO objects.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Currently only works on SUS systems and Ruby 1.9
13
+
14
+ == SYNOPSIS:
15
+
16
+ file = Tempfile.new('foo')
17
+ file.writev %w{ hello world }
18
+ assert_equal 'helloworld', File.read(file.path)
19
+ file.unlink
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * Ruby 1.9
24
+
25
+ == INSTALL:
26
+
27
+ * gem install writev
28
+
29
+ == LICENSE:
30
+
31
+ (The MIT License)
32
+
33
+ Copyright (c) 2011 Aaron Patterson
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ 'Software'), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
49
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
50
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
51
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
52
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ gem 'rake-compiler', '>= 0.4.1'
7
+ require "rake/extensiontask"
8
+
9
+ Hoe.plugins.delete :rubyforge
10
+ Hoe.plugin :minitest
11
+ Hoe.plugin :gemspec # `gem install hoe-gemspec`
12
+ Hoe.plugin :git # `gem install hoe-git`
13
+ Hoe.plugin :debugging # `gem install hoe-debugging`
14
+
15
+ Hoe.spec 'writev' do
16
+ developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
17
+ self.readme_file = 'README.rdoc'
18
+ self.history_file = 'CHANGELOG.rdoc'
19
+ self.extra_rdoc_files = FileList['*.rdoc']
20
+
21
+ extra_dev_deps << ['rake-compiler', '>= 0.4.1']
22
+
23
+ self.spec_extras = {
24
+ :extensions => ["ext/writev/extconf.rb"],
25
+ :required_ruby_version => '>= 1.9.2'
26
+ }
27
+
28
+ Rake::ExtensionTask.new "writev", spec do |ext|
29
+ ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
30
+ end
31
+ end
32
+
33
+ # vim: syntax=ruby
@@ -0,0 +1,29 @@
1
+ require 'writev'
2
+ require 'tempfile'
3
+ require 'benchmark'
4
+
5
+ LIST = File.readlines '/usr/share/dict/words'
6
+ p LIST.length
7
+
8
+ Benchmark.bm(7) do |x|
9
+ x.report('write') {
10
+ file = Tempfile.new('write')
11
+ LIST.each { |l| file.write l }
12
+ file.unlink
13
+ }
14
+ x.report('writev') {
15
+ file = Tempfile.new('write1')
16
+ LIST.each_slice(IO::IOV_MAX) do |slice|
17
+ file.writev slice
18
+ end
19
+ file.unlink
20
+ }
21
+ end
22
+
23
+ # /* vim: set et sws=2 sw=2: */
24
+ __END__
25
+ [aaron@higgins writev (master)]$ ruby -I lib bench.rb
26
+ 235886
27
+ user system total real
28
+ write 0.270000 0.010000 0.280000 ( 0.293202)
29
+ writev 0.020000 0.040000 0.060000 ( 0.087576)
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile 'writev'
@@ -0,0 +1,59 @@
1
+ #include <ruby.h>
2
+ #include <ruby/io.h>
3
+ #include <sys/uio.h>
4
+
5
+ VALUE rb_IOV_MAX;
6
+
7
+ static VALUE
8
+ rb_io_check_io(VALUE io)
9
+ {
10
+ return rb_check_convert_type(io, T_FILE, "IO", "to_io");
11
+ }
12
+
13
+ #define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
14
+
15
+ static VALUE rb_writev(VALUE io, VALUE list)
16
+ {
17
+ rb_io_t * fptr;
18
+ struct iovec * iov;
19
+ long i;
20
+ ssize_t written;
21
+ VALUE tmp;
22
+
23
+ #ifdef IOV_MAX
24
+ if(RARRAY_LEN(list) > IOV_MAX)
25
+ #else
26
+ if(RARRAY_LEN(list) > NUM2INT(rb_IOV_MAX))
27
+ #endif
28
+ rb_raise(rb_eArgError, "list is too long");
29
+
30
+ tmp = rb_io_check_io(io);
31
+ GetOpenFile(tmp, fptr);
32
+ rb_io_check_writable(fptr);
33
+
34
+ iov = xcalloc(RARRAY_LEN(list), sizeof(struct iovec));
35
+
36
+ for(i = 0; i < RARRAY_LEN(list); i++) {
37
+ VALUE string = rb_ary_entry(list, i);
38
+ iov[i].iov_base = StringValuePtr(string);
39
+ iov[i].iov_len = RSTRING_LEN(string);
40
+ }
41
+
42
+ if((written = writev(fptr->fd, iov, (int)RARRAY_LEN(list))) == -1)
43
+ rb_sys_fail_path(fptr->pathv);
44
+
45
+ return LONG2FIX(written);
46
+ }
47
+
48
+ void Init_writev()
49
+ {
50
+ rb_define_method(rb_cIO, "writev", rb_writev, 1);
51
+ #ifdef IOV_MAX
52
+ rb_IOV_MAX = INT2NUM(IOV_MAX);
53
+ #else
54
+ rb_IOV_MAX = INT2NUM(sysconf(_SC_IOV_MAX));
55
+ #endif
56
+ rb_define_const(rb_cIO, "IOV_MAX", rb_IOV_MAX);
57
+ }
58
+
59
+ /* vim: set noet sws=4 sw=4: */
@@ -0,0 +1,5 @@
1
+ require 'writev.so'
2
+
3
+ module WriteV
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,37 @@
1
+ require 'minitest/autorun'
2
+ require 'writev'
3
+ require 'tempfile'
4
+
5
+ class TestWritev < MiniTest::Unit::TestCase
6
+ def test_writev
7
+ file = Tempfile.new('foo')
8
+
9
+ file.writev %w{ hello world }
10
+ assert_equal 'helloworld', File.read(file.path)
11
+ file.unlink
12
+ end
13
+
14
+ def test_length
15
+ file = Tempfile.new('foo')
16
+
17
+ assert_equal 'helloworld'.bytesize, file.writev(%w{ hello world })
18
+ file.unlink
19
+ end
20
+
21
+ def test_fail
22
+ File.open(__FILE__, 'r') do |f|
23
+ assert_raises(IOError) do
24
+ f.writev %w{ hello world }
25
+ end
26
+ end
27
+ end
28
+
29
+ def test_list_too_long
30
+ file = Tempfile.new('foo')
31
+ assert_raises(ArgumentError) do
32
+ file.writev %w{ x } * (IO::IOV_MAX + 1)
33
+ end
34
+ end
35
+ end
36
+
37
+ # /* vim: set et sws=2 sw=2: */
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: writev
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Aaron Patterson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-19 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: minitest
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 5
29
+ segments:
30
+ - 2
31
+ - 3
32
+ version: "2.3"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake-compiler
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 13
44
+ segments:
45
+ - 0
46
+ - 4
47
+ - 1
48
+ version: 0.4.1
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 17
60
+ segments:
61
+ - 2
62
+ - 9
63
+ version: "2.9"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: |-
67
+ This gem adds the `writev` method to IO. It provides access to the `writev`
68
+ system call on your IO objects.
69
+ email:
70
+ - aaron@tenderlovemaking.com
71
+ executables: []
72
+
73
+ extensions:
74
+ - ext/writev/extconf.rb
75
+ extra_rdoc_files:
76
+ - Manifest.txt
77
+ - CHANGELOG.rdoc
78
+ - README.rdoc
79
+ files:
80
+ - .autotest
81
+ - CHANGELOG.rdoc
82
+ - Manifest.txt
83
+ - README.rdoc
84
+ - Rakefile
85
+ - bench.rb
86
+ - ext/writev/extconf.rb
87
+ - ext/writev/writev.c
88
+ - lib/writev.rb
89
+ - test/test_writev.rb
90
+ - .gemtest
91
+ homepage: http://github.com/tenderlove/writev
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --main
97
+ - README.rdoc
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 55
106
+ segments:
107
+ - 1
108
+ - 9
109
+ - 2
110
+ version: 1.9.2
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project: writev
123
+ rubygems_version: 1.8.8
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: This gem adds the `writev` method to IO
127
+ test_files:
128
+ - test/test_writev.rb