nio4r 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/CHANGES.md +23 -0
- data/README.md +31 -6
- data/ext/libev/Changes +20 -1
- data/ext/libev/README +2 -1
- data/ext/libev/ev.c +109 -59
- data/ext/libev/ev.h +11 -10
- data/ext/libev/ev_epoll.c +25 -14
- data/ext/libev/ev_kqueue.c +11 -5
- data/ext/libev/ev_linuxaio.c +642 -0
- data/ext/libev/ev_poll.c +13 -8
- data/ext/libev/ev_port.c +5 -2
- data/ext/libev/ev_vars.h +12 -1
- data/ext/libev/ev_wrap.h +16 -0
- data/ext/nio4r/org/nio4r/Selector.java +5 -1
- data/lib/nio/version.rb +1 -1
- data/spec/nio/selector_spec.rb +23 -4
- metadata +4 -4
- data/LICENSE.txt +0 -20
data/ext/libev/ev_poll.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* libev poll fd activity backend
|
3
3
|
*
|
4
|
-
* Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
|
4
|
+
* Copyright (c) 2007,2008,2009,2010,2011,2016,2019 Marc Alexander Lehmann <libev@schmorp.de>
|
5
5
|
* All rights reserved.
|
6
6
|
*
|
7
7
|
* Redistribution and use in source and binary forms, with or without modifica-
|
@@ -41,10 +41,12 @@
|
|
41
41
|
|
42
42
|
inline_size
|
43
43
|
void
|
44
|
-
|
44
|
+
array_needsize_pollidx (int *base, int offset, int count)
|
45
45
|
{
|
46
|
-
/*
|
47
|
-
* to
|
46
|
+
/* using memset (.., -1, ...) is tempting, we we try
|
47
|
+
* to be ultraportable
|
48
|
+
*/
|
49
|
+
base += offset;
|
48
50
|
while (count--)
|
49
51
|
*base++ = -1;
|
50
52
|
}
|
@@ -57,14 +59,14 @@ poll_modify (EV_P_ int fd, int oev, int nev)
|
|
57
59
|
if (oev == nev)
|
58
60
|
return;
|
59
61
|
|
60
|
-
array_needsize (int, pollidxs, pollidxmax, fd + 1,
|
62
|
+
array_needsize (int, pollidxs, pollidxmax, fd + 1, array_needsize_pollidx);
|
61
63
|
|
62
64
|
idx = pollidxs [fd];
|
63
65
|
|
64
66
|
if (idx < 0) /* need to allocate a new pollfd */
|
65
67
|
{
|
66
68
|
pollidxs [fd] = idx = pollcnt++;
|
67
|
-
array_needsize (struct pollfd, polls, pollmax, pollcnt,
|
69
|
+
array_needsize (struct pollfd, polls, pollmax, pollcnt, array_needsize_noinit);
|
68
70
|
polls [idx].fd = fd;
|
69
71
|
}
|
70
72
|
|
@@ -108,14 +110,17 @@ poll_poll (EV_P_ ev_tstamp timeout)
|
|
108
110
|
else
|
109
111
|
for (p = polls; res; ++p)
|
110
112
|
{
|
111
|
-
assert (("libev: poll
|
113
|
+
assert (("libev: poll returned illegal result, broken BSD kernel?", p < polls + pollcnt));
|
112
114
|
|
113
115
|
if (expect_false (p->revents)) /* this expect is debatable */
|
114
116
|
{
|
115
117
|
--res;
|
116
118
|
|
117
119
|
if (expect_false (p->revents & POLLNVAL))
|
118
|
-
|
120
|
+
{
|
121
|
+
assert (("libev: poll found invalid fd in poll set", 0));
|
122
|
+
fd_kill (EV_A_ p->fd);
|
123
|
+
}
|
119
124
|
else
|
120
125
|
fd_event (
|
121
126
|
EV_A_
|
data/ext/libev/ev_port.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* libev solaris event port backend
|
3
3
|
*
|
4
|
-
* Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
|
4
|
+
* Copyright (c) 2007,2008,2009,2010,2011,2019 Marc Alexander Lehmann <libev@schmorp.de>
|
5
5
|
* All rights reserved.
|
6
6
|
*
|
7
7
|
* Redistribution and use in source and binary forms, with or without modifica-
|
@@ -69,7 +69,10 @@ port_associate_and_check (EV_P_ int fd, int ev)
|
|
69
69
|
)
|
70
70
|
{
|
71
71
|
if (errno == EBADFD)
|
72
|
-
|
72
|
+
{
|
73
|
+
assert (("libev: port_associate found invalid fd", errno != EBADFD);
|
74
|
+
fd_kill (EV_A_ fd);
|
75
|
+
}
|
73
76
|
else
|
74
77
|
ev_syserr ("(libev) port_associate");
|
75
78
|
}
|
data/ext/libev/ev_vars.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* loop member variable declarations
|
3
3
|
*
|
4
|
-
* Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de>
|
4
|
+
* Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2019 Marc Alexander Lehmann <libev@schmorp.de>
|
5
5
|
* All rights reserved.
|
6
6
|
*
|
7
7
|
* Redistribution and use in source and binary forms, with or without modifica-
|
@@ -107,6 +107,17 @@ VARx(int, epoll_epermcnt)
|
|
107
107
|
VARx(int, epoll_epermmax)
|
108
108
|
#endif
|
109
109
|
|
110
|
+
#if EV_USE_LINUXAIO || EV_GENWRAP
|
111
|
+
VARx(aio_context_t, linuxaio_ctx)
|
112
|
+
VARx(int, linuxaio_iteration)
|
113
|
+
VARx(struct aniocb **, linuxaio_iocbps)
|
114
|
+
VARx(int, linuxaio_iocbpmax)
|
115
|
+
VARx(struct iocb **, linuxaio_submits)
|
116
|
+
VARx(int, linuxaio_submitcnt)
|
117
|
+
VARx(int, linuxaio_submitmax)
|
118
|
+
VARx(ev_io, linuxaio_epoll_w)
|
119
|
+
#endif
|
120
|
+
|
110
121
|
#if EV_USE_KQUEUE || EV_GENWRAP
|
111
122
|
VARx(pid_t, kqueue_fd_pid)
|
112
123
|
VARx(struct kevent *, kqueue_changes)
|
data/ext/libev/ev_wrap.h
CHANGED
@@ -50,6 +50,14 @@
|
|
50
50
|
#define kqueue_eventmax ((loop)->kqueue_eventmax)
|
51
51
|
#define kqueue_events ((loop)->kqueue_events)
|
52
52
|
#define kqueue_fd_pid ((loop)->kqueue_fd_pid)
|
53
|
+
#define linuxaio_ctx ((loop)->linuxaio_ctx)
|
54
|
+
#define linuxaio_epoll_w ((loop)->linuxaio_epoll_w)
|
55
|
+
#define linuxaio_iocbpmax ((loop)->linuxaio_iocbpmax)
|
56
|
+
#define linuxaio_iocbps ((loop)->linuxaio_iocbps)
|
57
|
+
#define linuxaio_iteration ((loop)->linuxaio_iteration)
|
58
|
+
#define linuxaio_submitcnt ((loop)->linuxaio_submitcnt)
|
59
|
+
#define linuxaio_submitmax ((loop)->linuxaio_submitmax)
|
60
|
+
#define linuxaio_submits ((loop)->linuxaio_submits)
|
53
61
|
#define loop_count ((loop)->loop_count)
|
54
62
|
#define loop_depth ((loop)->loop_depth)
|
55
63
|
#define loop_done ((loop)->loop_done)
|
@@ -149,6 +157,14 @@
|
|
149
157
|
#undef kqueue_eventmax
|
150
158
|
#undef kqueue_events
|
151
159
|
#undef kqueue_fd_pid
|
160
|
+
#undef linuxaio_ctx
|
161
|
+
#undef linuxaio_epoll_w
|
162
|
+
#undef linuxaio_iocbpmax
|
163
|
+
#undef linuxaio_iocbps
|
164
|
+
#undef linuxaio_iteration
|
165
|
+
#undef linuxaio_submitcnt
|
166
|
+
#undef linuxaio_submitmax
|
167
|
+
#undef linuxaio_submits
|
152
168
|
#undef loop_count
|
153
169
|
#undef loop_depth
|
154
170
|
#undef loop_done
|
@@ -19,6 +19,7 @@ import org.jruby.anno.JRubyMethod;
|
|
19
19
|
import org.jruby.runtime.Block;
|
20
20
|
import org.jruby.runtime.ThreadContext;
|
21
21
|
import org.jruby.runtime.builtin.IRubyObject;
|
22
|
+
import org.jruby.util.io.OpenFile;
|
22
23
|
|
23
24
|
import org.nio4r.Monitor;
|
24
25
|
|
@@ -136,7 +137,10 @@ public class Selector extends RubyObject {
|
|
136
137
|
@JRubyMethod
|
137
138
|
public IRubyObject deregister(ThreadContext context, IRubyObject io) {
|
138
139
|
Ruby runtime = context.getRuntime();
|
139
|
-
|
140
|
+
OpenFile file = RubyIO.convertToIO(context, io).getOpenFileInitialized();
|
141
|
+
if (file.fd() == null)
|
142
|
+
return context.nil;
|
143
|
+
Channel rawChannel = file.channel();
|
140
144
|
|
141
145
|
if(!(rawChannel instanceof SelectableChannel)) {
|
142
146
|
throw runtime.newArgumentError("not a selectable IO object");
|
data/lib/nio/version.rb
CHANGED
data/spec/nio/selector_spec.rb
CHANGED
@@ -16,10 +16,12 @@ RSpec.describe NIO::Selector do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context "#initialize" do
|
19
|
-
it "allows explicitly specifying a backend" do
|
19
|
+
it "allows explicitly specifying a backend" do |example|
|
20
20
|
backend = described_class.backends.first
|
21
21
|
selector = described_class.new(backend)
|
22
22
|
expect(selector.backend).to eq backend
|
23
|
+
|
24
|
+
example.reporter.message "Supported backends: #{described_class.backends}"
|
23
25
|
end
|
24
26
|
|
25
27
|
it "raises ArgumentError if given an invalid backend" do
|
@@ -32,8 +34,10 @@ RSpec.describe NIO::Selector do
|
|
32
34
|
end
|
33
35
|
|
34
36
|
context "backend" do
|
35
|
-
it "knows its backend" do
|
37
|
+
it "knows its backend" do |example|
|
36
38
|
expect(subject.backend).to be_a Symbol
|
39
|
+
|
40
|
+
example.reporter.message "Current backend: #{subject.backend}"
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
@@ -67,6 +71,15 @@ RSpec.describe NIO::Selector do
|
|
67
71
|
expect(monitor).to be_closed
|
68
72
|
end
|
69
73
|
|
74
|
+
it "allows deregistering closed IO objects" do
|
75
|
+
subject.register(reader, :r)
|
76
|
+
reader.close
|
77
|
+
|
78
|
+
expect do
|
79
|
+
subject.deregister(reader)
|
80
|
+
end.not_to raise_error
|
81
|
+
end
|
82
|
+
|
70
83
|
it "reports if it is empty" do
|
71
84
|
expect(subject).to be_empty
|
72
85
|
subject.register(reader, :r)
|
@@ -91,14 +104,20 @@ RSpec.describe NIO::Selector do
|
|
91
104
|
|
92
105
|
context "timeouts" do
|
93
106
|
let(:select_precision) {0.2}
|
107
|
+
let(:timeout) {2.0}
|
94
108
|
let(:payload) {"hi there"}
|
95
109
|
|
96
|
-
it "waits for
|
110
|
+
it "waits for timeout when selecting from empty selector" do
|
111
|
+
started_at = Time.now
|
112
|
+
expect(subject.select(timeout)).to be_nil
|
113
|
+
expect(Time.now - started_at).to be_within(select_precision).of(timeout)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "waits for a timeout when selecting with reader" do
|
97
117
|
monitor = subject.register(reader, :r)
|
98
118
|
|
99
119
|
writer << payload
|
100
120
|
|
101
|
-
timeout = 0.5
|
102
121
|
started_at = Time.now
|
103
122
|
expect(subject.select(timeout)).to include monitor
|
104
123
|
expect(Time.now - started_at).to be_within(select_precision).of(0)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nio4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,7 +54,6 @@ files:
|
|
54
54
|
- CHANGES.md
|
55
55
|
- Gemfile
|
56
56
|
- Guardfile
|
57
|
-
- LICENSE.txt
|
58
57
|
- README.md
|
59
58
|
- Rakefile
|
60
59
|
- appveyor.yml
|
@@ -66,6 +65,7 @@ files:
|
|
66
65
|
- ext/libev/ev.h
|
67
66
|
- ext/libev/ev_epoll.c
|
68
67
|
- ext/libev/ev_kqueue.c
|
68
|
+
- ext/libev/ev_linuxaio.c
|
69
69
|
- ext/libev/ev_poll.c
|
70
70
|
- ext/libev/ev_port.c
|
71
71
|
- ext/libev/ev_select.c
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
|
-
rubygems_version: 3.0.
|
125
|
+
rubygems_version: 3.0.4
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: New IO for Ruby
|
data/LICENSE.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2011-2018 Tony Arcieri
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|