sendfile 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +13 -17
- data/ext/extconf.rb +21 -19
- data/ext/sendfile.c +37 -17
- data/sendfile.gemspec +3 -5
- metadata +26 -49
data/README.textile
CHANGED
@@ -1,31 +1,27 @@
|
|
1
1
|
h1. Ruby sendfile(2) Interface
|
2
2
|
|
3
|
-
This module allows Ruby programs to access their OS's native
|
4
|
-
<code>sendfile(2)</code> system call from any IO object. Your kernel must
|
5
|
-
export a recognized signature for the <code>sendfile(2)</code> system call
|
6
|
-
to use this module. Currently, that includes Linux, Solaris
|
7
|
-
and FreeBSD.
|
3
|
+
This module allows Ruby programs to access their OS's native <code>sendfile(2)</code> system call from any IO object. Your kernel must export a recognized signature for the <code>sendfile(2)</code> system call to use this module. Currently, that includes Linux, Solaris and FreeBSD.
|
8
4
|
|
9
5
|
h2. Installation
|
10
6
|
|
11
|
-
Download and install the latest package from the rubyforge.org
|
12
|
-
RubyGems repository.
|
7
|
+
Download and install the latest package from the rubyforge.org RubyGems repository.
|
13
8
|
|
14
|
-
|
9
|
+
<code>
|
10
|
+
$ gem install sendfile
|
11
|
+
</code>
|
15
12
|
|
16
|
-
If the tests all pass, you're ready to start using sendfile
|
13
|
+
If the tests all pass, you're ready to start using sendfile!
|
17
14
|
|
18
15
|
h2. Usage
|
19
16
|
|
20
17
|
Here's a small example of a use of <code>IO#sendfile</code>.
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
bc.. require 'socket'
|
20
|
+
require 'rubygems'
|
21
|
+
require 'sendfile'
|
22
|
+
s = TCPSocket.new 'yourdomain.com', 5000
|
23
|
+
File.open 'somefile.txt' { |f| s.sendfile f }
|
24
|
+
s.close
|
28
25
|
|
29
|
-
See the test scripts for more examples on how to use this
|
30
|
-
module.
|
26
|
+
p. See the test scripts for more examples on how to use this module.
|
31
27
|
|
data/ext/extconf.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
#
|
1
|
+
#
|
2
2
|
# Copyright (c) 2005 Tobias DiPasquale
|
3
3
|
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
5
5
|
# copy of this software and associated documentation files (the "Software"),
|
6
6
|
# to deal in the Software without restriction, including without limitation
|
7
|
-
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8
|
-
# and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
9
9
|
# Software is furnished to do so, subject to the following conditions:
|
10
10
|
#
|
11
|
-
# The above copyright notice and this permission notice shall be included
|
11
|
+
# The above copyright notice and this permission notice shall be included
|
12
12
|
# in all copies or substantial portions of the Software.
|
13
13
|
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
15
|
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
17
|
-
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
19
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
17
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
19
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
20
20
|
# DEALINGS IN THE SOFTWARE.
|
21
21
|
#
|
22
22
|
|
@@ -28,16 +28,19 @@ require 'mkmf'
|
|
28
28
|
$config_h = ""
|
29
29
|
case RUBY_PLATFORM
|
30
30
|
when /solaris/
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
have_header( "sys/sendfile.h")
|
32
|
+
have_library( "sendfile", "sendfile")
|
33
|
+
$config_h << "#define RUBY_PLATFORM_SOLARIS"
|
34
34
|
when /linux/
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
have_header( "sys/sendfile.h")
|
36
|
+
have_library( "c", "sendfile")
|
37
|
+
$config_h << "#define RUBY_PLATFORM_LINUX"
|
38
38
|
when /freebsd/
|
39
|
-
|
40
|
-
|
39
|
+
have_library( "c", "sendfile")
|
40
|
+
$config_h << "#define RUBY_PLATFORM_FREEBSD"
|
41
|
+
when /darwin/
|
42
|
+
have_library( "c", "sendfile")
|
43
|
+
$config_h << "#define RUBY_PLATFORM_DARWIN"
|
41
44
|
end
|
42
45
|
|
43
46
|
File.open( "config.h", "w") do |f|
|
@@ -51,4 +54,3 @@ end
|
|
51
54
|
|
52
55
|
have_func('rb_thread_blocking_region')
|
53
56
|
create_makefile( "sendfile")
|
54
|
-
|
data/ext/sendfile.c
CHANGED
@@ -3,22 +3,22 @@
|
|
3
3
|
*
|
4
4
|
* Copyright (c) 2005,2008 Tobias DiPasquale
|
5
5
|
*
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
7
7
|
* copy of this software and associated documentation files (the "Software"),
|
8
8
|
* to deal in the Software without restriction, including without limitation
|
9
|
-
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
10
|
-
* and/or sell copies of the Software, and to permit persons to whom the
|
9
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
10
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
11
11
|
* Software is furnished to do so, subject to the following conditions:
|
12
12
|
*
|
13
|
-
* The above copyright notice and this permission notice shall be included
|
13
|
+
* The above copyright notice and this permission notice shall be included
|
14
14
|
* in all copies or substantial portions of the Software.
|
15
15
|
*
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
17
17
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19
|
-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
-
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
22
22
|
* DEALINGS IN THE SOFTWARE.
|
23
23
|
*
|
24
24
|
* ------------------------------------------------------------------------
|
@@ -91,6 +91,10 @@ rb_thread_blocking_region(
|
|
91
91
|
# include <unistd.h>
|
92
92
|
#elif defined(RUBY_PLATFORM_SOLARIS)
|
93
93
|
# include <sys/sendfile.h>
|
94
|
+
#elif defined(RUBY_PLATFORM_DARWIN)
|
95
|
+
# include <sys/types.h>
|
96
|
+
# include <sys/socket.h>
|
97
|
+
# include <sys/uio.h>
|
94
98
|
#endif
|
95
99
|
|
96
100
|
static size_t count_max(off_t count)
|
@@ -138,7 +142,7 @@ static VALUE nogvl_sendfile(void *data)
|
|
138
142
|
size_t w = count_max(args->count);
|
139
143
|
|
140
144
|
rv = sendfile(args->in, args->out, args->off, args->count,
|
141
|
-
|
145
|
+
NULL, &written, 0);
|
142
146
|
if (written == 0 && rv == 0) {
|
143
147
|
args->eof = 1;
|
144
148
|
} else {
|
@@ -148,6 +152,23 @@ static VALUE nogvl_sendfile(void *data)
|
|
148
152
|
|
149
153
|
return (VALUE)rv;
|
150
154
|
}
|
155
|
+
#elif defined(RUBY_PLATFORM_DARWIN)
|
156
|
+
static VALUE nogvl_sendfile(void *data)
|
157
|
+
{
|
158
|
+
struct sendfile_args *args = data;
|
159
|
+
int rv;
|
160
|
+
off_t written;
|
161
|
+
size_t w = count_max(args->count);
|
162
|
+
|
163
|
+
rv = sendfile(args->in, args->out, args->off, args->count,
|
164
|
+
NULL, 0);
|
165
|
+
if (rv == 0)
|
166
|
+
args->eof = 1;
|
167
|
+
if (rv > 0)
|
168
|
+
args->count -= rv;
|
169
|
+
|
170
|
+
return (VALUE)rv;
|
171
|
+
}
|
151
172
|
#else
|
152
173
|
static VALUE nogvl_sendfile(void *data)
|
153
174
|
{
|
@@ -172,7 +193,7 @@ static off_t sendfile_full(struct sendfile_args *args)
|
|
172
193
|
|
173
194
|
while (1) {
|
174
195
|
rv = (ssize_t)rb_thread_blocking_region(nogvl_sendfile, args,
|
175
|
-
|
196
|
+
RUBY_UBF_IO, NULL);
|
176
197
|
if (!args->count)
|
177
198
|
break;
|
178
199
|
if (args->eof) {
|
@@ -201,7 +222,7 @@ static VALUE sendfile_nonblock(struct sendfile_args *args, int try)
|
|
201
222
|
}
|
202
223
|
|
203
224
|
rv = (ssize_t)rb_thread_blocking_region(nogvl_sendfile, args,
|
204
|
-
|
225
|
+
RUBY_UBF_IO, NULL);
|
205
226
|
if (rv < 0) {
|
206
227
|
if (try && errno == EAGAIN)
|
207
228
|
return sym_wait_writable;
|
@@ -217,7 +238,7 @@ static VALUE sendfile_nonblock(struct sendfile_args *args, int try)
|
|
217
238
|
}
|
218
239
|
|
219
240
|
static void convert_args(int argc, VALUE *argv, VALUE self,
|
220
|
-
|
241
|
+
struct sendfile_args *args)
|
221
242
|
{
|
222
243
|
VALUE in, offset, count;
|
223
244
|
|
@@ -232,7 +253,7 @@ static void convert_args(int argc, VALUE *argv, VALUE self,
|
|
232
253
|
args->off = (NIL_P(offset)) ? 0 : NUM2OFFT(offset);
|
233
254
|
if (NIL_P(count)) {
|
234
255
|
/* FreeBSD's sendfile() can take 0 as an indication to send
|
235
|
-
* until end of file, but Linux and Solaris can't, and anyway
|
256
|
+
* until end of file, but Linux and Solaris can't, and anyway
|
236
257
|
* we need the file size to ensure we send it all in the case
|
237
258
|
* of a non-blocking fd */
|
238
259
|
struct stat s;
|
@@ -299,7 +320,7 @@ static VALUE rb_io_sendfile_nonblock(int argc, VALUE *argv, VALUE self)
|
|
299
320
|
|
300
321
|
/* call-seq:
|
301
322
|
* writeIO.trysendfile(readIO, offset=0, count=nil) => integer, nil, or
|
302
|
-
*
|
323
|
+
* :wait_writable
|
303
324
|
*
|
304
325
|
* Transfers count bytes starting at offset from readIO directly to writeIO
|
305
326
|
* without copying (i.e. invoking the kernel to do it for you).
|
@@ -338,7 +359,6 @@ void Init_sendfile(void)
|
|
338
359
|
sym_wait_writable = ID2SYM(rb_intern("wait_writable"));
|
339
360
|
rb_define_method(rb_cIO, "sendfile", rb_io_sendfile, -1);
|
340
361
|
rb_define_method(rb_cIO, "sendfile_nonblock",
|
341
|
-
|
362
|
+
rb_io_sendfile_nonblock, -1);
|
342
363
|
rb_define_method(rb_cIO, "trysendfile", rb_io_trysendfile, -1);
|
343
364
|
}
|
344
|
-
|
data/sendfile.gemspec
CHANGED
@@ -2,22 +2,20 @@
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gs|
|
4
4
|
gs.name = 'sendfile'
|
5
|
-
gs.version = '1.
|
5
|
+
gs.version = '1.2.0'
|
6
6
|
gs.summary = 'Ruby interface to sendfile(2) system call'
|
7
7
|
gs.description = <<-EOF
|
8
8
|
Allows Ruby programs to access sendfile(2) functionality on
|
9
|
-
any IO object. Works on Linux, Solaris and
|
9
|
+
any IO object. Works on Linux, Solaris, FreeBSD and Darwin with
|
10
10
|
blocking and non-blocking sockets.
|
11
11
|
EOF
|
12
12
|
gs.author = 'Toby DiPasquale'
|
13
13
|
gs.email = 'toby@cbcg.net'
|
14
|
+
gs.homepage = 'https://github.com/codeslinger/sendfile'
|
14
15
|
gs.rubyforge_project = 'ruby-sendfile'
|
15
|
-
|
16
|
-
gs.autorequire = 'sendfile'
|
17
16
|
gs.files = File.read('FILES').split($/)
|
18
17
|
gs.test_files = Dir.glob 'test/test_*.rb'
|
19
18
|
gs.extensions << 'ext/extconf.rb'
|
20
|
-
|
21
19
|
gs.has_rdoc = true
|
22
20
|
gs.extra_rdoc_files = %w(README.textile)
|
23
21
|
gs.required_ruby_version = '>= 1.8.0'
|
metadata
CHANGED
@@ -1,37 +1,26 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendfile
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 1.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Toby DiPasquale
|
14
|
-
autorequire:
|
9
|
+
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-03-05 00:00:00 -05:00
|
19
|
-
default_executable:
|
12
|
+
date: 2013-06-30 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
any IO object. Works on Linux, Solaris and FreeBSD with
|
25
|
-
blocking and non-blocking sockets.
|
26
|
-
|
14
|
+
description: ! "Allows Ruby programs to access sendfile(2) functionality on \nany
|
15
|
+
IO object. Works on Linux, Solaris, FreeBSD and Darwin with\nblocking and non-blocking
|
16
|
+
sockets.\n"
|
27
17
|
email: toby@cbcg.net
|
28
18
|
executables: []
|
29
|
-
|
30
|
-
extensions:
|
19
|
+
extensions:
|
31
20
|
- ext/extconf.rb
|
32
|
-
extra_rdoc_files:
|
21
|
+
extra_rdoc_files:
|
33
22
|
- README.textile
|
34
|
-
files:
|
23
|
+
files:
|
35
24
|
- FILES
|
36
25
|
- README.textile
|
37
26
|
- LICENSE
|
@@ -42,41 +31,29 @@ files:
|
|
42
31
|
- test/large.gz
|
43
32
|
- test/small
|
44
33
|
- sendfile.gemspec
|
45
|
-
|
46
|
-
homepage:
|
34
|
+
homepage: https://github.com/codeslinger/sendfile
|
47
35
|
licenses: []
|
48
|
-
|
49
36
|
post_install_message:
|
50
37
|
rdoc_options: []
|
51
|
-
|
52
|
-
require_paths:
|
38
|
+
require_paths:
|
53
39
|
- lib
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
41
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 55
|
60
|
-
segments:
|
61
|
-
- 1
|
62
|
-
- 8
|
63
|
-
- 0
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
64
45
|
version: 1.8.0
|
65
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
47
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
version: "0"
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
74
52
|
requirements: []
|
75
|
-
|
76
53
|
rubyforge_project: ruby-sendfile
|
77
|
-
rubygems_version: 1.
|
54
|
+
rubygems_version: 1.8.23
|
78
55
|
signing_key:
|
79
56
|
specification_version: 3
|
80
57
|
summary: Ruby interface to sendfile(2) system call
|
81
|
-
test_files:
|
58
|
+
test_files:
|
82
59
|
- test/test_sendfile.rb
|