sleepy_penguin 3.1.0 → 3.1.0.26.g7181
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.wrongdoc.yml +2 -0
- data/LICENSE +1 -2
- data/README +4 -3
- data/ext/sleepy_penguin/epoll.c +114 -552
- data/ext/sleepy_penguin/eventfd.c +7 -7
- data/ext/sleepy_penguin/extconf.rb +2 -2
- data/ext/sleepy_penguin/init.c +19 -0
- data/ext/sleepy_penguin/inotify.c +63 -57
- data/ext/sleepy_penguin/missing_epoll.h +1 -1
- data/ext/sleepy_penguin/missing_inotify.h +2 -2
- data/ext/sleepy_penguin/signalfd.c +8 -7
- data/ext/sleepy_penguin/sleepy_penguin.h +47 -10
- data/ext/sleepy_penguin/timerfd.c +9 -9
- data/ext/sleepy_penguin/util.c +18 -14
- data/lib/sleepy_penguin.rb +16 -0
- data/lib/sleepy_penguin/epoll.rb +264 -0
- data/lib/sleepy_penguin/epoll/io.rb +28 -0
- data/lib/sleepy_penguin/sp.rb +1 -1
- data/sleepy_penguin.gemspec +1 -3
- data/test/test_epoll.rb +29 -8
- data/test/test_epoll_gc.rb +2 -0
- data/test/test_epoll_gc_per_thread.rb +23 -0
- data/test/test_epoll_io.rb +24 -0
- data/test/test_epoll_optimizations.rb +1 -1
- data/test/test_eventfd.rb +5 -0
- data/test/test_inotify.rb +5 -13
- data/test/test_timerfd.rb +5 -0
- metadata +69 -71
- data/ext/sleepy_penguin/epoll_green.h +0 -95
data/test/test_epoll.rb
CHANGED
@@ -26,12 +26,12 @@ class TestEpoll < Test::Unit::TestCase
|
|
26
26
|
|
27
27
|
def test_cross_thread
|
28
28
|
tmp = []
|
29
|
-
Thread.new { sleep 0.100; @ep.add(@wr, Epoll::OUT) }
|
30
29
|
t0 = Time.now
|
30
|
+
Thread.new { sleep 0.100; @ep.add(@wr, Epoll::OUT) }
|
31
31
|
@ep.wait { |flags,obj| tmp << [ flags, obj ] }
|
32
32
|
elapsed = Time.now - t0
|
33
33
|
assert elapsed >= 0.100
|
34
|
-
assert_equal [[Epoll::OUT, @wr]], tmp
|
34
|
+
assert_equal [[Epoll::OUT, @wr]], tmp, tmp.inspect
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_fork_safe
|
@@ -48,6 +48,19 @@ class TestEpoll < Test::Unit::TestCase
|
|
48
48
|
assert_equal [[Epoll::IN, @rd]], tmp
|
49
49
|
end
|
50
50
|
|
51
|
+
def test_dup_and_fork
|
52
|
+
epdup = @ep.dup
|
53
|
+
@ep.close
|
54
|
+
assert ! epdup.closed?
|
55
|
+
pid = fork do
|
56
|
+
exit(!epdup.closed? && @ep.closed?)
|
57
|
+
end
|
58
|
+
_, status = Process.waitpid2(pid)
|
59
|
+
assert status.success?, status.inspect
|
60
|
+
ensure
|
61
|
+
epdup.close
|
62
|
+
end
|
63
|
+
|
51
64
|
def test_after_fork_usability
|
52
65
|
fork { @ep.add(@rd, Epoll::IN); exit!(0) }
|
53
66
|
fork { @ep.set(@rd, Epoll::IN); exit!(0) }
|
@@ -345,7 +358,11 @@ class TestEpoll < Test::Unit::TestCase
|
|
345
358
|
def test_new
|
346
359
|
@ep.close
|
347
360
|
io = Epoll.new.to_io
|
348
|
-
|
361
|
+
if RUBY_VERSION.to_f >= 2.0
|
362
|
+
assert_equal 1, io.fcntl(Fcntl::F_GETFD)
|
363
|
+
else
|
364
|
+
assert_equal 0, io.fcntl(Fcntl::F_GETFD)
|
365
|
+
end
|
349
366
|
end
|
350
367
|
|
351
368
|
def test_delete
|
@@ -399,7 +416,7 @@ class TestEpoll < Test::Unit::TestCase
|
|
399
416
|
def test_include?
|
400
417
|
assert ! @ep.include?(@rd)
|
401
418
|
@ep.add @rd, Epoll::IN
|
402
|
-
assert @ep.include?(@rd)
|
419
|
+
assert @ep.include?(@rd), @ep.instance_variable_get(:@marks).inspect
|
403
420
|
assert @ep.include?(@rd.fileno)
|
404
421
|
assert ! @ep.include?(@wr)
|
405
422
|
assert ! @ep.include?(@wr.fileno)
|
@@ -473,22 +490,26 @@ class TestEpoll < Test::Unit::TestCase
|
|
473
490
|
nr = 10
|
474
491
|
nr.times do
|
475
492
|
r, w = IO.pipe
|
476
|
-
pipes[r] = w
|
493
|
+
lock.synchronize { pipes[r] = w }
|
477
494
|
@ep.add(r, Epoll::IN | Epoll::ET | Epoll::ONESHOT)
|
478
495
|
|
479
496
|
t = Thread.new do
|
480
497
|
sleep 2
|
481
498
|
events = 0
|
482
499
|
@ep.wait(maxevents) do |_,obj|
|
483
|
-
|
484
|
-
|
500
|
+
lock.synchronize do
|
501
|
+
assert pipes.include?(obj), "#{obj.inspect} is unknown"
|
502
|
+
ok << obj
|
503
|
+
end
|
485
504
|
events += 1
|
486
505
|
end
|
487
506
|
events
|
488
507
|
end
|
489
508
|
thr << t
|
490
509
|
end
|
491
|
-
|
510
|
+
lock.synchronize do
|
511
|
+
pipes.each_value { |w| w.syswrite '.' }
|
512
|
+
end
|
492
513
|
thr.each do |t|
|
493
514
|
begin
|
494
515
|
t.run
|
data/test/test_epoll_gc.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
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
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fcntl'
|
3
|
+
require 'socket'
|
4
|
+
require 'thread'
|
5
|
+
$-w = true
|
6
|
+
Thread.abort_on_exception = true
|
7
|
+
require 'sleepy_penguin'
|
8
|
+
|
9
|
+
class TestEpollIO < Test::Unit::TestCase
|
10
|
+
include SleepyPenguin
|
11
|
+
RBX = defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'rbx')
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@rd, @wr = IO.pipe
|
15
|
+
@epio = Epoll::IO.new(nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_add_wait
|
19
|
+
@epio.epoll_ctl(Epoll::CTL_ADD, @wr, Epoll::OUT)
|
20
|
+
ev = []
|
21
|
+
@epio.epoll_wait { |events, obj| ev << [ events, obj ] }
|
22
|
+
assert_equal([[Epoll::OUT, @wr]], ev)
|
23
|
+
end
|
24
|
+
end
|
@@ -28,7 +28,7 @@ class TestEpollOptimizations < Test::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
assert_nil err
|
30
30
|
lines = io.readlines; io.close
|
31
|
-
assert_equal 1, lines.grep(/^epoll_ctl/).size
|
31
|
+
assert_equal 1, lines.grep(/^epoll_ctl/).size, lines.inspect
|
32
32
|
assert_match(/EPOLL_CTL_ADD/, lines.grep(/^epoll_ctl/)[0])
|
33
33
|
|
34
34
|
io, err = Strace.me { @ep.set(@wr, Epoll::OUT | Epoll::ONESHOT) }
|
data/test/test_eventfd.rb
CHANGED
@@ -20,6 +20,11 @@ class TestEventFD < Test::Unit::TestCase
|
|
20
20
|
def test_new
|
21
21
|
efd = EventFD.new 0
|
22
22
|
assert_kind_of(IO, efd)
|
23
|
+
if RUBY_VERSION.to_f >= 2.0
|
24
|
+
assert_equal 1, efd.fcntl(Fcntl::F_GETFD)
|
25
|
+
else
|
26
|
+
assert_equal 0, efd.fcntl(Fcntl::F_GETFD)
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
def test_new_nonblock
|
data/test/test_inotify.rb
CHANGED
@@ -17,6 +17,11 @@ class TestInotify < Test::Unit::TestCase
|
|
17
17
|
def test_new
|
18
18
|
@ino = Inotify.new
|
19
19
|
assert_kind_of(IO, ino)
|
20
|
+
if RUBY_VERSION.to_f >= 2.0
|
21
|
+
assert_equal 1, ino.fcntl(Fcntl::F_GETFD)
|
22
|
+
else
|
23
|
+
assert_equal 0, ino.fcntl(Fcntl::F_GETFD)
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
def test_constants
|
@@ -30,19 +35,6 @@ class TestInotify < Test::Unit::TestCase
|
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
33
|
-
def test_dup
|
34
|
-
a = Inotify.new
|
35
|
-
b = a.dup
|
36
|
-
assert a.fileno != b.fileno
|
37
|
-
abuf = a.instance_variable_get(:@inotify_buf)
|
38
|
-
bbuf = b.instance_variable_get(:@inotify_buf)
|
39
|
-
assert abuf.object_id != bbuf.object_id, "#{a.inspect} #{b.inspect}"
|
40
|
-
|
41
|
-
atmp = a.instance_variable_get(:@inotify_tmp)
|
42
|
-
btmp = b.instance_variable_get(:@inotify_tmp)
|
43
|
-
assert_equal atmp.object_id, btmp.object_id
|
44
|
-
end
|
45
|
-
|
46
38
|
def test_new_nonblock
|
47
39
|
ino = Inotify.new Inotify::NONBLOCK
|
48
40
|
flags = ino.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK
|
data/test/test_timerfd.rb
CHANGED
@@ -15,6 +15,11 @@ class TestTimerFD < Test::Unit::TestCase
|
|
15
15
|
def test_create
|
16
16
|
tfd = TimerFD.new
|
17
17
|
assert_kind_of(IO, tfd)
|
18
|
+
if RUBY_VERSION.to_f >= 2.0
|
19
|
+
assert_equal 1, tfd.fcntl(Fcntl::F_GETFD)
|
20
|
+
else
|
21
|
+
assert_equal 0, tfd.fcntl(Fcntl::F_GETFD)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
def test_create_nonblock
|
metadata
CHANGED
@@ -1,68 +1,67 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sleepy_penguin
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 3
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 3.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.1.0.26.g7181
|
5
|
+
prerelease: 9
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- sleepy_penguin hackers
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: wrongdoc
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 5
|
32
|
-
version: "1.5"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
33
22
|
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: strace_me
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: strace_me
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
39
33
|
none: false
|
40
|
-
requirements:
|
34
|
+
requirements:
|
41
35
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 1
|
46
|
-
- 0
|
47
|
-
version: "1.0"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.0'
|
48
38
|
type: :development
|
49
|
-
|
50
|
-
|
51
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.0'
|
46
|
+
description: ! 'sleepy_penguin provides access to newer, Linux-only system calls to
|
47
|
+
wait
|
48
|
+
|
52
49
|
on events from traditionally non-I/O sources. Bindings to the eventfd,
|
53
|
-
|
50
|
+
|
51
|
+
timerfd, inotify, and epoll interfaces are provided.'
|
54
52
|
email: sleepy.penguin@librelist.org
|
55
53
|
executables: []
|
56
|
-
|
57
|
-
extensions:
|
54
|
+
extensions:
|
58
55
|
- ext/sleepy_penguin/extconf.rb
|
59
|
-
extra_rdoc_files:
|
56
|
+
extra_rdoc_files:
|
60
57
|
- LICENSE
|
61
58
|
- README
|
62
59
|
- TODO
|
63
60
|
- NEWS
|
64
61
|
- ChangeLog
|
65
62
|
- lib/sleepy_penguin.rb
|
63
|
+
- lib/sleepy_penguin/epoll.rb
|
64
|
+
- lib/sleepy_penguin/epoll/io.rb
|
66
65
|
- lib/sleepy_penguin/signalfd/sig_info.rb
|
67
66
|
- lib/sleepy_penguin/sp.rb
|
68
67
|
- ext/sleepy_penguin/epoll.c
|
@@ -71,7 +70,7 @@ extra_rdoc_files:
|
|
71
70
|
- ext/sleepy_penguin/inotify.c
|
72
71
|
- ext/sleepy_penguin/signalfd.c
|
73
72
|
- ext/sleepy_penguin/timerfd.c
|
74
|
-
files:
|
73
|
+
files:
|
75
74
|
- .document
|
76
75
|
- .gitignore
|
77
76
|
- .manifest
|
@@ -88,7 +87,6 @@ files:
|
|
88
87
|
- Rakefile
|
89
88
|
- TODO
|
90
89
|
- ext/sleepy_penguin/epoll.c
|
91
|
-
- ext/sleepy_penguin/epoll_green.h
|
92
90
|
- ext/sleepy_penguin/eventfd.c
|
93
91
|
- ext/sleepy_penguin/extconf.rb
|
94
92
|
- ext/sleepy_penguin/init.c
|
@@ -103,6 +101,8 @@ files:
|
|
103
101
|
- ext/sleepy_penguin/util.c
|
104
102
|
- ext/sleepy_penguin/value2timespec.h
|
105
103
|
- lib/sleepy_penguin.rb
|
104
|
+
- lib/sleepy_penguin/epoll.rb
|
105
|
+
- lib/sleepy_penguin/epoll/io.rb
|
106
106
|
- lib/sleepy_penguin/signalfd/sig_info.rb
|
107
107
|
- lib/sleepy_penguin/sp.rb
|
108
108
|
- pkg.mk
|
@@ -110,55 +110,53 @@ files:
|
|
110
110
|
- sleepy_penguin.gemspec
|
111
111
|
- test/test_epoll.rb
|
112
112
|
- test/test_epoll_gc.rb
|
113
|
+
- test/test_epoll_io.rb
|
113
114
|
- test/test_epoll_optimizations.rb
|
114
115
|
- test/test_eventfd.rb
|
115
116
|
- test/test_inotify.rb
|
116
117
|
- test/test_signalfd.rb
|
117
118
|
- test/test_signalfd_siginfo.rb
|
118
119
|
- test/test_timerfd.rb
|
120
|
+
- test/test_epoll_gc_per_thread.rb
|
119
121
|
homepage: http://bogomips.org/sleepy_penguin/
|
120
|
-
licenses:
|
121
|
-
|
122
|
+
licenses:
|
123
|
+
- LGPLv2.1
|
124
|
+
- LGPLv3
|
122
125
|
post_install_message:
|
123
|
-
rdoc_options:
|
126
|
+
rdoc_options:
|
124
127
|
- -t
|
125
128
|
- sleepy_penguin - Linux I/O events for Ruby
|
126
129
|
- -W
|
127
130
|
- http://bogomips.org/sleepy_penguin.git/tree/%s
|
128
|
-
require_paths:
|
131
|
+
require_paths:
|
129
132
|
- lib
|
130
|
-
|
131
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
134
|
none: false
|
133
|
-
requirements:
|
134
|
-
- -
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
|
137
|
-
|
138
|
-
- 0
|
139
|
-
version: "0"
|
140
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
140
|
none: false
|
142
|
-
requirements:
|
143
|
-
- -
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
version: "0"
|
141
|
+
requirements:
|
142
|
+
- - ! '>'
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 1.3.1
|
149
145
|
requirements: []
|
150
|
-
|
151
146
|
rubyforge_project: rainbows
|
152
147
|
rubygems_version: 1.8.24
|
153
148
|
signing_key:
|
154
149
|
specification_version: 3
|
155
150
|
summary: Linux I/O events for Ruby
|
156
|
-
test_files:
|
157
|
-
- test/
|
158
|
-
- test/test_signalfd_siginfo.rb
|
159
|
-
- test/test_epoll.rb
|
160
|
-
- test/test_signalfd.rb
|
151
|
+
test_files:
|
152
|
+
- test/test_epoll_gc.rb
|
161
153
|
- test/test_inotify.rb
|
154
|
+
- test/test_signalfd.rb
|
155
|
+
- test/test_epoll.rb
|
156
|
+
- test/test_epoll_gc_per_thread.rb
|
162
157
|
- test/test_eventfd.rb
|
163
|
-
- test/test_epoll_gc.rb
|
164
158
|
- test/test_timerfd.rb
|
159
|
+
- test/test_signalfd_siginfo.rb
|
160
|
+
- test/test_epoll_optimizations.rb
|
161
|
+
- test/test_epoll_io.rb
|
162
|
+
has_rdoc:
|
@@ -1,95 +0,0 @@
|
|
1
|
-
/* this file is only used by Matz Ruby 1.8 which used green threads */
|
2
|
-
|
3
|
-
/*
|
4
|
-
* we have to worry about green threads and always pass zero
|
5
|
-
* as the timeout for epoll_wait :(
|
6
|
-
*/
|
7
|
-
#include <rubysig.h>
|
8
|
-
#include <sys/time.h>
|
9
|
-
|
10
|
-
/* in case _BSD_SOURCE doesn't give us this macro */
|
11
|
-
#ifndef timersub
|
12
|
-
# define timersub(a, b, result) \
|
13
|
-
do { \
|
14
|
-
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
15
|
-
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
16
|
-
if ((result)->tv_usec < 0) { \
|
17
|
-
--(result)->tv_sec; \
|
18
|
-
(result)->tv_usec += 1000000; \
|
19
|
-
} \
|
20
|
-
} while (0)
|
21
|
-
#endif
|
22
|
-
|
23
|
-
static int safe_epoll_wait(struct ep_per_thread *ept)
|
24
|
-
{
|
25
|
-
int n;
|
26
|
-
|
27
|
-
do {
|
28
|
-
TRAP_BEG;
|
29
|
-
n = epoll_wait(ept->ep->fd, ept->events, ept->maxevents, 0);
|
30
|
-
TRAP_END;
|
31
|
-
} while (n == -1 && errno == EINTR && ep_fd_check(ept->ep));
|
32
|
-
|
33
|
-
return n;
|
34
|
-
}
|
35
|
-
|
36
|
-
static int epwait_forever(struct ep_per_thread *ept)
|
37
|
-
{
|
38
|
-
int n;
|
39
|
-
|
40
|
-
do {
|
41
|
-
(void)rb_io_wait_readable(ept->ep->fd);
|
42
|
-
n = safe_epoll_wait(ept);
|
43
|
-
} while (n == 0);
|
44
|
-
|
45
|
-
return n;
|
46
|
-
}
|
47
|
-
|
48
|
-
static int epwait_timed(struct ep_per_thread *ept)
|
49
|
-
{
|
50
|
-
struct timeval tv;
|
51
|
-
|
52
|
-
tv.tv_sec = ept->timeout / 1000;
|
53
|
-
tv.tv_usec = (ept->timeout % 1000) * 1000;
|
54
|
-
|
55
|
-
for (;;) {
|
56
|
-
struct timeval t0, now, diff;
|
57
|
-
int n;
|
58
|
-
int fd = ept->ep->fd;
|
59
|
-
fd_set rfds;
|
60
|
-
|
61
|
-
FD_ZERO(&rfds);
|
62
|
-
FD_SET(fd, &rfds);
|
63
|
-
|
64
|
-
gettimeofday(&t0, NULL);
|
65
|
-
(void)rb_thread_select(fd + 1, &rfds, NULL, NULL, &tv);
|
66
|
-
n = safe_epoll_wait(ept);
|
67
|
-
if (n != 0)
|
68
|
-
return n;
|
69
|
-
|
70
|
-
/* XXX use CLOCK_MONOTONIC if people care about 1.8... */
|
71
|
-
gettimeofday(&now, NULL);
|
72
|
-
timersub(&now, &t0, &diff);
|
73
|
-
timersub(&tv, &diff, &tv);
|
74
|
-
|
75
|
-
if (tv.tv_usec < 0 || tv.tv_sec < 0)
|
76
|
-
return (n == -1) ? 0 : n;
|
77
|
-
}
|
78
|
-
|
79
|
-
assert("should never get here (epwait_timed)");
|
80
|
-
return -1;
|
81
|
-
}
|
82
|
-
|
83
|
-
static VALUE real_epwait(struct ep_per_thread *ept)
|
84
|
-
{
|
85
|
-
int n;
|
86
|
-
|
87
|
-
if (ept->timeout == -1)
|
88
|
-
n = epwait_forever(ept);
|
89
|
-
else if (ept->timeout == 0)
|
90
|
-
n = safe_epoll_wait(ept);
|
91
|
-
else
|
92
|
-
n = epwait_timed(ept);
|
93
|
-
|
94
|
-
return epwait_result(ept, n);
|
95
|
-
}
|