sleepy_penguin 3.1.0.26.g7181 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +1 -0
- data/.gitignore +1 -0
- data/GIT-VERSION-GEN +8 -1
- data/GNUmakefile +1 -0
- data/README +6 -4
- data/ext/sleepy_penguin/epoll.c +11 -12
- data/ext/sleepy_penguin/extconf.rb +5 -1
- data/ext/sleepy_penguin/init.c +19 -0
- data/ext/sleepy_penguin/kqueue.c +675 -0
- data/ext/sleepy_penguin/sleepy_penguin.h +12 -0
- data/ext/sleepy_penguin/value2timespec.h +1 -1
- data/lib/sleepy_penguin.rb +0 -6
- data/lib/sleepy_penguin/epoll.rb +29 -24
- data/lib/sleepy_penguin/kevent.rb +7 -0
- data/lib/sleepy_penguin/kqueue.rb +122 -0
- data/lib/sleepy_penguin/kqueue/io.rb +30 -0
- data/pkg.mk +1 -1
- data/test/test_constants.rb +16 -0
- data/test/test_epoll.rb +37 -52
- data/test/test_epoll_io.rb +13 -2
- data/test/test_epoll_optimizations.rb +0 -1
- data/test/test_inotify.rb +1 -1
- data/test/test_kqueue.rb +75 -0
- data/test/test_kqueue_io.rb +114 -0
- data/test/test_timerfd.rb +2 -2
- metadata +30 -16
- data/test/test_epoll_gc_per_thread.rb +0 -23
data/test/test_epoll_io.rb
CHANGED
@@ -8,7 +8,6 @@ require 'sleepy_penguin'
|
|
8
8
|
|
9
9
|
class TestEpollIO < Test::Unit::TestCase
|
10
10
|
include SleepyPenguin
|
11
|
-
RBX = defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'rbx')
|
12
11
|
|
13
12
|
def setup
|
14
13
|
@rd, @wr = IO.pipe
|
@@ -21,4 +20,16 @@ class TestEpollIO < Test::Unit::TestCase
|
|
21
20
|
@epio.epoll_wait { |events, obj| ev << [ events, obj ] }
|
22
21
|
assert_equal([[Epoll::OUT, @wr]], ev)
|
23
22
|
end
|
24
|
-
|
23
|
+
|
24
|
+
class EpSub < Epoll::IO
|
25
|
+
def self.new
|
26
|
+
super(SleepyPenguin::Epoll::CLOEXEC)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_subclass
|
31
|
+
tmp = EpSub.new
|
32
|
+
assert_equal Fcntl::FD_CLOEXEC, tmp.fcntl(Fcntl::F_GETFD)
|
33
|
+
assert_nil tmp.close
|
34
|
+
end
|
35
|
+
end if defined?(SleepyPenguin::Epoll)
|
data/test/test_inotify.rb
CHANGED
data/test/test_kqueue.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$-w = true
|
3
|
+
Thread.abort_on_exception = true
|
4
|
+
require 'sleepy_penguin'
|
5
|
+
|
6
|
+
class TestKqueue < Test::Unit::TestCase
|
7
|
+
include SleepyPenguin
|
8
|
+
|
9
|
+
def test_kqueue
|
10
|
+
kq = Kqueue.new
|
11
|
+
assert_kind_of IO, kq.to_io
|
12
|
+
rd, wr = IO.pipe
|
13
|
+
ev = Kevent[rd.fileno, EvFilt::READ, Ev::ADD|Ev::ONESHOT, 0, 0, rd]
|
14
|
+
thr = Thread.new do
|
15
|
+
kq.kevent(ev)
|
16
|
+
wr.syswrite "."
|
17
|
+
end
|
18
|
+
|
19
|
+
events = []
|
20
|
+
n = kq.kevent(nil, 1) do |kevent|
|
21
|
+
assert_kind_of Kevent, kevent
|
22
|
+
events << kevent
|
23
|
+
end
|
24
|
+
assert_equal 1, events.size
|
25
|
+
assert_equal rd.fileno, events[0][0]
|
26
|
+
assert_equal EvFilt::READ, events[0][1]
|
27
|
+
assert_equal 1, n
|
28
|
+
|
29
|
+
# we should be drained
|
30
|
+
events = []
|
31
|
+
n = kq.kevent(nil, 1, 0) do |kevent|
|
32
|
+
assert_kind_of Kevent, kevent
|
33
|
+
events << kevent
|
34
|
+
end
|
35
|
+
assert_equal 0, events.size
|
36
|
+
assert_equal 0, n
|
37
|
+
thr.join
|
38
|
+
|
39
|
+
# synchronous add
|
40
|
+
events = []
|
41
|
+
ev = Kevent[wr.fileno, EvFilt::WRITE, Ev::ADD|Ev::ONESHOT, 0, 0, wr]
|
42
|
+
kq.kevent(ev)
|
43
|
+
n = kq.kevent(nil, 1, 0) do |kevent|
|
44
|
+
assert_kind_of Kevent, kevent
|
45
|
+
events << kevent
|
46
|
+
end
|
47
|
+
assert_equal 1, events.size
|
48
|
+
assert_equal wr.fileno, events[0][0]
|
49
|
+
assert_equal EvFilt::WRITE, events[0][1]
|
50
|
+
assert_equal 1, n
|
51
|
+
ensure
|
52
|
+
kq.close
|
53
|
+
rd.close if rd
|
54
|
+
wr.close if wr
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_usable_after_fork
|
58
|
+
kq = Kqueue.new
|
59
|
+
pid = fork do
|
60
|
+
begin
|
61
|
+
ok = false
|
62
|
+
assert_equal(0, kq.kevent(nil, 1, 0.1) { exit!(false) })
|
63
|
+
ok = true
|
64
|
+
ensure
|
65
|
+
exit!(ok)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
assert_equal(0, kq.kevent(nil, 1, 0.1) { exit!(false) })
|
69
|
+
_, status = Process.waitpid2(pid)
|
70
|
+
assert status.success?, status.inspect
|
71
|
+
ensure
|
72
|
+
kq.close
|
73
|
+
end
|
74
|
+
end if defined?(SleepyPenguin::Kqueue) &&
|
75
|
+
IO.instance_methods.include?(:autoclose=)
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$-w = true
|
3
|
+
Thread.abort_on_exception = true
|
4
|
+
require 'sleepy_penguin'
|
5
|
+
|
6
|
+
class TestKqueueIO < Test::Unit::TestCase
|
7
|
+
include SleepyPenguin
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@to_close = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@to_close.each do |io|
|
15
|
+
io.close unless io.closed?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_io_like
|
20
|
+
kq = Kqueue::IO.new
|
21
|
+
@to_close << kq
|
22
|
+
assert_equal kq, kq.to_io
|
23
|
+
assert_kind_of Integer, kq.fileno
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_bad_type
|
27
|
+
kq = Kqueue::IO.new
|
28
|
+
@to_close << kq
|
29
|
+
assert_raises(TypeError) { kq.kevent("HI") }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_multi_event
|
33
|
+
kq = Kqueue::IO.new
|
34
|
+
@to_close << kq
|
35
|
+
list = []
|
36
|
+
pipes = [ IO.pipe, IO.pipe, IO.pipe, IO.pipe ]
|
37
|
+
pipes.each do |(r,w)|
|
38
|
+
@to_close << r
|
39
|
+
@to_close << w
|
40
|
+
list << Kevent[r.fileno, EvFilt::READ, Ev::ADD|Ev::ONESHOT, 0, 0, r]
|
41
|
+
end
|
42
|
+
kq.kevent(list)
|
43
|
+
|
44
|
+
pipes.each do |(_,w)|
|
45
|
+
w.syswrite('.')
|
46
|
+
end
|
47
|
+
received = []
|
48
|
+
seen = {}
|
49
|
+
kq.kevent(nil, 1) do |*args|
|
50
|
+
received << args
|
51
|
+
assert_equal 6, args.size
|
52
|
+
assert_kind_of IO, args[5]
|
53
|
+
assert_nil seen[args[5]]
|
54
|
+
seen[args[5]] = true
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_equal 1, received.size
|
58
|
+
|
59
|
+
kq.kevent(nil, 666) do |*args|
|
60
|
+
received << args
|
61
|
+
assert_equal 6, args.size
|
62
|
+
assert_kind_of IO, args[5]
|
63
|
+
assert_nil seen[args[5]]
|
64
|
+
seen[args[5]] = true
|
65
|
+
end
|
66
|
+
assert_equal 4, received.size
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_xthread
|
70
|
+
kq = Kqueue::IO.new
|
71
|
+
assert_kind_of IO, kq
|
72
|
+
rd, wr = IO.pipe
|
73
|
+
ev = Kevent[rd.fileno, EvFilt::READ, Ev::ADD|Ev::ONESHOT, 0, 0, rd]
|
74
|
+
thr = Thread.new do
|
75
|
+
kq.kevent(ev)
|
76
|
+
wr.syswrite "."
|
77
|
+
end
|
78
|
+
|
79
|
+
events = []
|
80
|
+
n = kq.kevent(nil, 1) do |ident,filter,flags,fflags,data,udata|
|
81
|
+
events << [ ident,filter,flags,fflags,data,udata ]
|
82
|
+
end
|
83
|
+
assert_equal 1, events.size
|
84
|
+
assert_equal rd.fileno, events[0][0]
|
85
|
+
assert_equal EvFilt::READ, events[0][1]
|
86
|
+
assert_equal 1, n
|
87
|
+
|
88
|
+
thr.join
|
89
|
+
|
90
|
+
# we should be drained
|
91
|
+
events = []
|
92
|
+
n = kq.kevent(nil, 1, 0) do |ident,filter,flags,fflags,data,udata|
|
93
|
+
events << [ ident,filter,flags,fflags,data,udata ]
|
94
|
+
end
|
95
|
+
assert_equal 0, events.size
|
96
|
+
assert_equal 0, n
|
97
|
+
|
98
|
+
# synchronous add
|
99
|
+
events = []
|
100
|
+
ev = Kevent[wr.fileno, EvFilt::WRITE, Ev::ADD|Ev::ONESHOT, 0, 0, wr]
|
101
|
+
kq.kevent(ev)
|
102
|
+
n = kq.kevent(nil, 1, 0) do |ident,filter,flags,fflags,data,udata|
|
103
|
+
events << [ ident,filter,flags,fflags,data,udata ]
|
104
|
+
end
|
105
|
+
assert_equal 1, events.size
|
106
|
+
assert_equal wr.fileno, events[0][0]
|
107
|
+
assert_equal EvFilt::WRITE, events[0][1]
|
108
|
+
assert_equal 1, n
|
109
|
+
ensure
|
110
|
+
kq.close
|
111
|
+
rd.close if rd
|
112
|
+
wr.close if wr
|
113
|
+
end
|
114
|
+
end if defined?(SleepyPenguin::Kqueue::IO)
|
data/test/test_timerfd.rb
CHANGED
@@ -65,9 +65,9 @@ class TestTimerFD < Test::Unit::TestCase
|
|
65
65
|
|
66
66
|
def test_expirations_nonblock
|
67
67
|
tfd = TimerFD.new(:MONOTONIC)
|
68
|
-
assert_equal([0, 0], tfd.settime(0, 0, 0.
|
68
|
+
assert_equal([0, 0], tfd.settime(0, 0, 0.05))
|
69
69
|
assert_nil tfd.expirations(true)
|
70
|
-
sleep 0.
|
70
|
+
sleep 0.05
|
71
71
|
assert_equal 1, tfd.expirations
|
72
72
|
end
|
73
73
|
end if defined?(SleepyPenguin::TimerFD)
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sleepy_penguin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
5
|
-
prerelease:
|
4
|
+
version: 3.2.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- sleepy_penguin hackers
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: wrongdoc
|
@@ -48,7 +48,9 @@ description: ! 'sleepy_penguin provides access to newer, Linux-only system calls
|
|
48
48
|
|
49
49
|
on events from traditionally non-I/O sources. Bindings to the eventfd,
|
50
50
|
|
51
|
-
timerfd, inotify, and epoll interfaces are provided.
|
51
|
+
timerfd, inotify, and epoll interfaces are provided. Experimental support
|
52
|
+
|
53
|
+
for kqueue on FreeBSD (and likely OpenBSD/NetBSD) are also provided.'
|
52
54
|
email: sleepy.penguin@librelist.org
|
53
55
|
executables: []
|
54
56
|
extensions:
|
@@ -62,6 +64,9 @@ extra_rdoc_files:
|
|
62
64
|
- lib/sleepy_penguin.rb
|
63
65
|
- lib/sleepy_penguin/epoll.rb
|
64
66
|
- lib/sleepy_penguin/epoll/io.rb
|
67
|
+
- lib/sleepy_penguin/kevent.rb
|
68
|
+
- lib/sleepy_penguin/kqueue.rb
|
69
|
+
- lib/sleepy_penguin/kqueue/io.rb
|
65
70
|
- lib/sleepy_penguin/signalfd/sig_info.rb
|
66
71
|
- lib/sleepy_penguin/sp.rb
|
67
72
|
- ext/sleepy_penguin/epoll.c
|
@@ -70,6 +75,7 @@ extra_rdoc_files:
|
|
70
75
|
- ext/sleepy_penguin/inotify.c
|
71
76
|
- ext/sleepy_penguin/signalfd.c
|
72
77
|
- ext/sleepy_penguin/timerfd.c
|
78
|
+
- ext/sleepy_penguin/kqueue.c
|
73
79
|
files:
|
74
80
|
- .document
|
75
81
|
- .gitignore
|
@@ -89,8 +95,10 @@ files:
|
|
89
95
|
- ext/sleepy_penguin/epoll.c
|
90
96
|
- ext/sleepy_penguin/eventfd.c
|
91
97
|
- ext/sleepy_penguin/extconf.rb
|
98
|
+
- ext/sleepy_penguin/git_version.h
|
92
99
|
- ext/sleepy_penguin/init.c
|
93
100
|
- ext/sleepy_penguin/inotify.c
|
101
|
+
- ext/sleepy_penguin/kqueue.c
|
94
102
|
- ext/sleepy_penguin/missing_epoll.h
|
95
103
|
- ext/sleepy_penguin/missing_inotify.h
|
96
104
|
- ext/sleepy_penguin/missing_rb_thread_fd_close.h
|
@@ -103,21 +111,26 @@ files:
|
|
103
111
|
- lib/sleepy_penguin.rb
|
104
112
|
- lib/sleepy_penguin/epoll.rb
|
105
113
|
- lib/sleepy_penguin/epoll/io.rb
|
114
|
+
- lib/sleepy_penguin/kevent.rb
|
115
|
+
- lib/sleepy_penguin/kqueue.rb
|
116
|
+
- lib/sleepy_penguin/kqueue/io.rb
|
106
117
|
- lib/sleepy_penguin/signalfd/sig_info.rb
|
107
118
|
- lib/sleepy_penguin/sp.rb
|
108
119
|
- pkg.mk
|
109
120
|
- setup.rb
|
110
121
|
- sleepy_penguin.gemspec
|
122
|
+
- test/test_constants.rb
|
111
123
|
- test/test_epoll.rb
|
112
124
|
- test/test_epoll_gc.rb
|
113
125
|
- test/test_epoll_io.rb
|
114
126
|
- test/test_epoll_optimizations.rb
|
115
127
|
- test/test_eventfd.rb
|
116
128
|
- test/test_inotify.rb
|
129
|
+
- test/test_kqueue.rb
|
130
|
+
- test/test_kqueue_io.rb
|
117
131
|
- test/test_signalfd.rb
|
118
132
|
- test/test_signalfd_siginfo.rb
|
119
133
|
- test/test_timerfd.rb
|
120
|
-
- test/test_epoll_gc_per_thread.rb
|
121
134
|
homepage: http://bogomips.org/sleepy_penguin/
|
122
135
|
licenses:
|
123
136
|
- LGPLv2.1
|
@@ -139,24 +152,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
153
|
none: false
|
141
154
|
requirements:
|
142
|
-
- - ! '
|
155
|
+
- - ! '>='
|
143
156
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
157
|
+
version: '0'
|
145
158
|
requirements: []
|
146
159
|
rubyforge_project: rainbows
|
147
|
-
rubygems_version: 1.8.
|
160
|
+
rubygems_version: 1.8.23
|
148
161
|
signing_key:
|
149
162
|
specification_version: 3
|
150
163
|
summary: Linux I/O events for Ruby
|
151
164
|
test_files:
|
152
|
-
- test/
|
153
|
-
- test/
|
154
|
-
- test/
|
165
|
+
- test/test_epoll_optimizations.rb
|
166
|
+
- test/test_constants.rb
|
167
|
+
- test/test_signalfd_siginfo.rb
|
155
168
|
- test/test_epoll.rb
|
156
|
-
- test/
|
169
|
+
- test/test_signalfd.rb
|
170
|
+
- test/test_kqueue_io.rb
|
171
|
+
- test/test_inotify.rb
|
172
|
+
- test/test_kqueue.rb
|
157
173
|
- test/test_eventfd.rb
|
158
|
-
- test/
|
159
|
-
- test/test_signalfd_siginfo.rb
|
160
|
-
- test/test_epoll_optimizations.rb
|
174
|
+
- test/test_epoll_gc.rb
|
161
175
|
- test/test_epoll_io.rb
|
162
|
-
|
176
|
+
- test/test_timerfd.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
__END__
|
2
|
-
require 'test/unit'
|
3
|
-
$-w = true
|
4
|
-
require 'sleepy_penguin'
|
5
|
-
|
6
|
-
class TestEpollGcPerThread < Test::Unit::TestCase
|
7
|
-
include SleepyPenguin
|
8
|
-
|
9
|
-
def test_per_thread_gc_storm
|
10
|
-
thr = []
|
11
|
-
pipes = []
|
12
|
-
100000.times do
|
13
|
-
t = Thread.new do
|
14
|
-
ep = Epoll.new
|
15
|
-
ep.add(r, Epoll::IN)
|
16
|
-
ep.wait { |
|
17
|
-
end
|
18
|
-
|
19
|
-
thr << t
|
20
|
-
if thr.size > 100
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|