nio4r 2.4.0-java → 2.5.0-java

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.
@@ -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
- pollidx_init (int *base, int count)
44
+ array_needsize_pollidx (int *base, int offset, int count)
45
45
  {
46
- /* consider using memset (.., -1, ...), which is practically guaranteed
47
- * to work on all systems implementing poll */
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, pollidx_init);
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, EMPTY2);
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() returned illegal result, broken BSD kernel?", p < polls + pollcnt));
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
- fd_kill (EV_A_ p->fd);
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_
@@ -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
- fd_kill (EV_A_ fd);
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
  }
@@ -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)
@@ -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
- Channel rawChannel = RubyIO.convertToIO(context, io).getChannel();
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");
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NIO
4
- VERSION = "2.4.0"
4
+ VERSION = "2.5.0"
5
5
  end
@@ -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 a timeout when selecting" do
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.0
4
+ version: 2.5.0
5
5
  platform: java
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-09 00:00:00.000000000 Z
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,6 @@ files:
53
53
  - CHANGES.md
54
54
  - Gemfile
55
55
  - Guardfile
56
- - LICENSE.txt
57
56
  - README.md
58
57
  - Rakefile
59
58
  - appveyor.yml
@@ -65,6 +64,7 @@ files:
65
64
  - ext/libev/ev.h
66
65
  - ext/libev/ev_epoll.c
67
66
  - ext/libev/ev_kqueue.c
67
+ - ext/libev/ev_linuxaio.c
68
68
  - ext/libev/ev_poll.c
69
69
  - ext/libev/ev_port.c
70
70
  - ext/libev/ev_select.c
@@ -123,8 +123,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.7.4
126
+ rubygems_version: 2.7.6
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: New IO for Ruby
130
- test_files: []
130
+ test_files:
131
+ - spec/nio/acceptables_spec.rb
132
+ - spec/nio/bytebuffer_spec.rb
133
+ - spec/nio/monitor_spec.rb
134
+ - spec/nio/selectables/pipe_spec.rb
135
+ - spec/nio/selectables/ssl_socket_spec.rb
136
+ - spec/nio/selectables/tcp_socket_spec.rb
137
+ - spec/nio/selectables/udp_socket_spec.rb
138
+ - spec/nio/selector_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/support/selectable_examples.rb
@@ -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.