io-wait 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac9aac81de884ac5961c9415e4347be5f26ae3ef6e52854834c76a105e4f7388
4
- data.tar.gz: 118b4011fcaa3f94a48ff2d3be11db1b2049375f709426b177ab5a9bc4799d7f
3
+ metadata.gz: 43e7f91045efd73e51af1a6e055afe646fc95d1b7c1a154453d915e6a213d223
4
+ data.tar.gz: 4d542bfb7bde6053c4069f451d41f39e05b77d0ebab5514532f601466ca57bba
5
5
  SHA512:
6
- metadata.gz: 58cf2bc5cdc614eb7827a460decf662def72676011fbf9d4a853dfd71b66311dd10d81fcd100ac0a2d676d61009e6e3a4c80ac0f7c7d0d88f303a8a16f1510de
7
- data.tar.gz: 700343ef7233d37f9e27d22bfab091af07e681e996619c8953553152b7b7598bb1843d2d969b8d268cac752ead4641b13f32380d2b5c43e8d4808e4176b64c89
6
+ metadata.gz: f78dc92e4500c196b69d87fb47f13f426f4a2d9b8532e69027d3c96a8dd93514d08c77adc421b8d3cac2e0aaf2f80d92327c98d95969a9816111b41c373fe10a
7
+ data.tar.gz: 4b2b4af88c93ddc7d12d1060f6f638aab6fc75178a32fe9810478a5b95e27575cbe1054c1e46964b7ca1eec1269f47b64bf823a990472363cb97c75236b4a438
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in io-wait.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem "rake"
8
+ gem "rake-compiler"
9
+ gem "test-unit"
10
+ gem 'ruby-maven', :platforms => :jruby
11
+ end
data/ext/io/wait/depend CHANGED
@@ -2,7 +2,7 @@
2
2
  wait.o: $(RUBY_EXTCONF_H)
3
3
  wait.o: $(arch_hdrdir)/ruby/config.h
4
4
  wait.o: $(hdrdir)/ruby.h
5
- wait.o: $(hdrdir)/ruby/assert.h
5
+ # wait.o: $(hdrdir)/ruby/assert.h # not in 2.6
6
6
  wait.o: $(hdrdir)/ruby/backward.h
7
7
  wait.o: $(hdrdir)/ruby/defines.h
8
8
  wait.o: $(hdrdir)/ruby/encoding.h
@@ -1,19 +1,24 @@
1
1
  # frozen_string_literal: false
2
2
  require 'mkmf'
3
- target = "io/wait"
4
3
 
5
- unless macro_defined?("DOSISH", "#include <ruby.h>")
6
- have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil
7
- fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h|
8
- have_macro("FIONREAD", [h, ioctl_h].compact)
9
- end
10
- if fionread
11
- $defs << "-DFIONREAD_HEADER=\"<#{fionread}>\""
12
- create_makefile(target)
13
- end
4
+ if RUBY_VERSION < "2.6"
5
+ File.write("Makefile", dummy_makefile($srcdir).join(""))
14
6
  else
15
- if have_func("rb_w32_ioctlsocket", "ruby.h")
16
- have_func("rb_w32_is_socket", "ruby.h")
17
- create_makefile(target)
7
+ target = "io/wait"
8
+ have_func("rb_io_wait")
9
+ unless macro_defined?("DOSISH", "#include <ruby.h>")
10
+ have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil
11
+ fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h|
12
+ have_macro("FIONREAD", [h, ioctl_h].compact)
13
+ end
14
+ if fionread
15
+ $defs << "-DFIONREAD_HEADER=\"<#{fionread}>\""
16
+ create_makefile(target)
17
+ end
18
+ else
19
+ if have_func("rb_w32_ioctlsocket", "ruby.h")
20
+ have_func("rb_w32_is_socket", "ruby.h")
21
+ create_makefile(target)
22
+ end
18
23
  end
19
24
  end
data/ext/io/wait/wait.c CHANGED
@@ -40,23 +40,57 @@
40
40
  #define FIONREAD_POSSIBLE_P(fd) ((void)(fd),Qtrue)
41
41
  #endif
42
42
 
43
+ #ifndef HAVE_RB_IO_WAIT
44
+ static VALUE io_ready_p _((VALUE io));
45
+ static VALUE io_wait_readable _((int argc, VALUE *argv, VALUE io));
46
+ static VALUE io_wait_writable _((int argc, VALUE *argv, VALUE io));
47
+ void Init_wait _((void));
48
+
49
+ static struct timeval *
50
+ get_timeout(int argc, VALUE *argv, struct timeval *timerec)
51
+ {
52
+ VALUE timeout = Qnil;
53
+ rb_check_arity(argc, 0, 1);
54
+ if (!argc || NIL_P(timeout = argv[0])) {
55
+ return NULL;
56
+ }
57
+ else {
58
+ *timerec = rb_time_interval(timeout);
59
+ return timerec;
60
+ }
61
+ }
62
+
63
+ static int
64
+ wait_for_single_fd(rb_io_t *fptr, int events, struct timeval *tv)
65
+ {
66
+ int i = rb_wait_for_single_fd(fptr->fd, events, tv);
67
+ if (i < 0)
68
+ rb_sys_fail(0);
69
+ rb_io_check_closed(fptr);
70
+ return (i & events);
71
+ }
72
+ #endif
73
+
43
74
  /*
44
75
  * call-seq:
45
76
  * io.nread -> int
46
77
  *
47
78
  * Returns number of bytes that can be read without blocking.
48
79
  * Returns zero if no information available.
80
+ *
81
+ * You must require 'io/wait' to use this method.
49
82
  */
50
83
 
51
84
  static VALUE
52
85
  io_nread(VALUE io)
53
86
  {
54
- rb_io_t *fptr = NULL;
87
+ rb_io_t *fptr;
88
+ int len;
55
89
  ioctl_arg n;
56
90
 
57
91
  GetOpenFile(io, fptr);
58
92
  rb_io_check_readable(fptr);
59
- int len = rb_io_read_pending(fptr);
93
+ len = rb_io_read_pending(fptr);
60
94
  if (len > 0) return INT2FIX(len);
61
95
  if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0);
62
96
  if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0);
@@ -64,6 +98,7 @@ io_nread(VALUE io)
64
98
  return INT2FIX(0);
65
99
  }
66
100
 
101
+ #ifdef HAVE_RB_IO_WAIT
67
102
  static VALUE
68
103
  io_wait_event(VALUE io, int event, VALUE timeout)
69
104
  {
@@ -82,81 +117,128 @@ io_wait_event(VALUE io, int event, VALUE timeout)
82
117
  return Qfalse;
83
118
  }
84
119
  }
120
+ #endif
85
121
 
86
122
  /*
87
123
  * call-seq:
88
- * io.ready? -> true or false
124
+ * io.ready? -> truthy or falsy
89
125
  *
90
- * Returns +true+ if input available without blocking, or +false+.
126
+ * Returns a truthy value if input available without blocking, or a
127
+ * falsy value.
128
+ *
129
+ * You must require 'io/wait' to use this method.
91
130
  */
92
131
 
93
132
  static VALUE
94
133
  io_ready_p(VALUE io)
95
134
  {
96
135
  rb_io_t *fptr;
136
+ #ifndef HAVE_RB_IO_WAIT
137
+ struct timeval tv = {0, 0};
138
+ #endif
97
139
 
98
140
  GetOpenFile(io, fptr);
99
141
  rb_io_check_readable(fptr);
100
142
  if (rb_io_read_pending(fptr)) return Qtrue;
101
143
 
102
- return io_wait_event(io, RUBY_IO_READABLE, RB_INT2NUM(0));
144
+ #ifndef HAVE_RB_IO_WAIT
145
+ if (wait_for_single_fd(fptr, RB_WAITFD_IN, &tv))
146
+ return Qtrue;
147
+ #else
148
+ if (RTEST(io_wait_event(io, RUBY_IO_READABLE, RB_INT2NUM(0))))
149
+ return Qtrue;
150
+ #endif
151
+ return Qfalse;
103
152
  }
104
153
 
105
154
  /*
106
155
  * call-seq:
107
- * io.wait_readable -> true or false
108
- * io.wait_readable(timeout) -> true or false
156
+ * io.wait_readable -> truthy or falsy
157
+ * io.wait_readable(timeout) -> truthy or falsy
158
+ *
159
+ * Waits until IO is readable and returns a truthy value, or a falsy
160
+ * value when times out. Returns a truthy value immediately when
161
+ * buffered data is available.
109
162
  *
110
- * Waits until IO is readable and returns +true+, or
111
- * +false+ when times out.
112
- * Returns +true+ immediately when buffered data is available.
163
+ * You must require 'io/wait' to use this method.
113
164
  */
114
165
 
115
166
  static VALUE
116
167
  io_wait_readable(int argc, VALUE *argv, VALUE io)
117
168
  {
118
- rb_io_t *fptr = NULL;
169
+ rb_io_t *fptr;
170
+ #ifndef HAVE_RB_IO_WAIT
171
+ struct timeval timerec;
172
+ struct timeval *tv;
173
+ #endif
119
174
 
120
- RB_IO_POINTER(io, fptr);
175
+ GetOpenFile(io, fptr);
121
176
  rb_io_check_readable(fptr);
122
177
 
178
+ #ifndef HAVE_RB_IO_WAIT
179
+ tv = get_timeout(argc, argv, &timerec);
180
+ #endif
123
181
  if (rb_io_read_pending(fptr)) return Qtrue;
124
182
 
183
+ #ifndef HAVE_RB_IO_WAIT
184
+ if (wait_for_single_fd(fptr, RB_WAITFD_IN, tv)) {
185
+ return io;
186
+ }
187
+ return Qnil;
188
+ #else
125
189
  rb_check_arity(argc, 0, 1);
126
190
  VALUE timeout = (argc == 1 ? argv[0] : Qnil);
127
191
 
128
192
  return io_wait_event(io, RUBY_IO_READABLE, timeout);
193
+ #endif
129
194
  }
130
195
 
131
196
  /*
132
197
  * call-seq:
133
- * io.wait_writable -> true or false
134
- * io.wait_writable(timeout) -> true or false
198
+ * io.wait_writable -> truthy or falsy
199
+ * io.wait_writable(timeout) -> truthy or falsy
135
200
  *
136
- * Waits until IO is writable and returns +true+ or
137
- * +false+ when times out.
201
+ * Waits until IO is writable and returns a truthy value or a falsy
202
+ * value when times out.
203
+ *
204
+ * You must require 'io/wait' to use this method.
138
205
  */
139
206
  static VALUE
140
207
  io_wait_writable(int argc, VALUE *argv, VALUE io)
141
208
  {
142
- rb_io_t *fptr = NULL;
209
+ rb_io_t *fptr;
210
+ #ifndef HAVE_RB_IO_WAIT
211
+ struct timeval timerec;
212
+ struct timeval *tv;
213
+ #endif
143
214
 
144
- RB_IO_POINTER(io, fptr);
215
+ GetOpenFile(io, fptr);
145
216
  rb_io_check_writable(fptr);
146
217
 
218
+ #ifndef HAVE_RB_IO_WAIT
219
+ tv = get_timeout(argc, argv, &timerec);
220
+ if (wait_for_single_fd(fptr, RB_WAITFD_OUT, tv)) {
221
+ return io;
222
+ }
223
+ return Qnil;
224
+ #else
147
225
  rb_check_arity(argc, 0, 1);
148
226
  VALUE timeout = (argc == 1 ? argv[0] : Qnil);
149
227
 
150
228
  return io_wait_event(io, RUBY_IO_WRITABLE, timeout);
229
+ #endif
151
230
  }
152
231
 
232
+ #ifdef HAVE_RB_IO_WAIT
153
233
  /*
154
234
  * call-seq:
155
- * io.wait_priority -> true or false
156
- * io.wait_priority(timeout) -> true or false
235
+ * io.wait_priority -> truthy or falsy
236
+ * io.wait_priority(timeout) -> truthy or falsy
157
237
  *
158
- * Waits until IO is priority and returns +true+ or
159
- * +false+ when times out.
238
+ * Waits until IO is priority and returns a truthy value or a falsy
239
+ * value when times out.
240
+ *
241
+ * You must require 'io/wait' to use this method.
160
242
  */
161
243
  static VALUE
162
244
  io_wait_priority(int argc, VALUE *argv, VALUE io)
@@ -173,6 +255,7 @@ io_wait_priority(int argc, VALUE *argv, VALUE io)
173
255
 
174
256
  return io_wait_event(io, RUBY_IO_PRIORITY, timeout);
175
257
  }
258
+ #endif
176
259
 
177
260
  static int
178
261
  wait_mode_sym(VALUE mode)
@@ -210,24 +293,51 @@ wait_mode_sym(VALUE mode)
210
293
 
211
294
  /*
212
295
  * call-seq:
213
- * io.wait(events, timeout) -> event mask or false.
214
- * io.wait(timeout = nil, mode = :read) -> event mask or false.
296
+ * io.wait(events, timeout) -> truthy or falsy
297
+ * io.wait(timeout = nil, mode = :read) -> truthy or falsy.
215
298
  *
216
299
  * Waits until the IO becomes ready for the specified events and returns the
217
- * subset of events that become ready, or +false+ when times out.
300
+ * subset of events that become ready, or a falsy value when times out.
218
301
  *
219
302
  * The events can be a bit mask of +IO::READABLE+, +IO::WRITABLE+ or
220
303
  * +IO::PRIORITY+.
221
304
  *
222
- * Returns +true+ immediately when buffered data is available.
305
+ * Returns a truthy value immediately when buffered data is available.
223
306
  *
224
307
  * Optional parameter +mode+ is one of +:read+, +:write+, or
225
308
  * +:read_write+.
309
+ *
310
+ * You must require 'io/wait' to use this method.
226
311
  */
227
312
 
228
313
  static VALUE
229
314
  io_wait(int argc, VALUE *argv, VALUE io)
230
315
  {
316
+ #ifndef HAVE_RB_IO_WAIT
317
+ rb_io_t *fptr;
318
+ struct timeval timerec;
319
+ struct timeval *tv = NULL;
320
+ int event = 0;
321
+ int i;
322
+
323
+ GetOpenFile(io, fptr);
324
+ for (i = 0; i < argc; ++i) {
325
+ if (SYMBOL_P(argv[i])) {
326
+ event |= wait_mode_sym(argv[i]);
327
+ }
328
+ else {
329
+ *(tv = &timerec) = rb_time_interval(argv[i]);
330
+ }
331
+ }
332
+ /* rb_time_interval() and might_mode() might convert the argument */
333
+ rb_io_check_closed(fptr);
334
+ if (!event) event = RB_WAITFD_IN;
335
+ if ((event & RB_WAITFD_IN) && rb_io_read_pending(fptr))
336
+ return Qtrue;
337
+ if (wait_for_single_fd(fptr, event, tv))
338
+ return io;
339
+ return Qnil;
340
+ #else
231
341
  VALUE timeout = Qundef;
232
342
  rb_io_event_t events = 0;
233
343
 
@@ -264,6 +374,7 @@ io_wait(int argc, VALUE *argv, VALUE io)
264
374
  }
265
375
 
266
376
  return io_wait_event(io, events, timeout);
377
+ #endif
267
378
  }
268
379
 
269
380
  /*
@@ -284,5 +395,7 @@ Init_wait(void)
284
395
 
285
396
  rb_define_method(rb_cIO, "wait_readable", io_wait_readable, -1);
286
397
  rb_define_method(rb_cIO, "wait_writable", io_wait_writable, -1);
398
+ #ifdef HAVE_RB_IO_WAIT
287
399
  rb_define_method(rb_cIO, "wait_priority", io_wait_priority, -1);
400
+ #endif
288
401
  }
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-wait
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
+ - Charles Oliver Nutter
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2021-10-21 00:00:00.000000000 Z
12
+ date: 2022-05-09 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: Waits until IO is readable or writable without blocking.
14
15
  email:
15
16
  - nobu@ruby-lang.org
17
+ - headius@headius.com
16
18
  executables: []
17
19
  extensions:
18
20
  - ext/io/wait/extconf.rb
@@ -21,14 +23,9 @@ files:
21
23
  - COPYING
22
24
  - Gemfile
23
25
  - README.md
24
- - Rakefile
25
26
  - ext/io/wait/depend
26
27
  - ext/io/wait/extconf.rb
27
28
  - ext/io/wait/wait.c
28
- - io-wait.gemspec
29
- - rakelib/changelogs.rake
30
- - rakelib/epoch.rake
31
- - rakelib/version.rake
32
29
  homepage: https://github.com/ruby/io-wait
33
30
  licenses:
34
31
  - Ruby
@@ -44,14 +41,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
41
  requirements:
45
42
  - - ">="
46
43
  - !ruby/object:Gem::Version
47
- version: 3.0.0
44
+ version: '0'
48
45
  required_rubygems_version: !ruby/object:Gem::Requirement
49
46
  requirements:
50
47
  - - ">="
51
48
  - !ruby/object:Gem::Version
52
49
  version: '0'
53
50
  requirements: []
54
- rubygems_version: 3.3.0.dev
51
+ rubygems_version: 3.4.0.dev
55
52
  signing_key:
56
53
  specification_version: 4
57
54
  summary: Waits until IO is readable or writable without blocking.
data/Rakefile DELETED
@@ -1,16 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- name = "io/wait"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test/lib"
8
- t.ruby_opts << "-rhelper"
9
- t.test_files = FileList["test/**/test_*.rb"]
10
- end
11
-
12
- require 'rake/extensiontask'
13
- Rake::ExtensionTask.new(name)
14
- task :test => :compile
15
-
16
- task :default => :test
data/io-wait.gemspec DELETED
@@ -1,27 +0,0 @@
1
- _VERSION = "0.2.0"
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "io-wait"
5
- spec.version = _VERSION
6
- spec.authors = ["Nobu Nakada"]
7
- spec.email = ["nobu@ruby-lang.org"]
8
-
9
- spec.summary = %q{Waits until IO is readable or writable without blocking.}
10
- spec.description = %q{Waits until IO is readable or writable without blocking.}
11
- spec.homepage = "https://github.com/ruby/io-wait"
12
- spec.licenses = ["Ruby", "BSD-2-Clause"]
13
- spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
14
-
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = spec.homepage
17
-
18
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
- `git ls-files -z`.split("\x0").reject do |f|
20
- f.match(%r{\A(?:test|spec|features)/|\A\.(?:git|travis)})
21
- end
22
- end
23
- spec.extensions = %w[ext/io/wait/extconf.rb]
24
- spec.bindir = "exe"
25
- spec.executables = []
26
- spec.require_paths = ["lib"]
27
- end
@@ -1,34 +0,0 @@
1
- task "build" => "changelogs"
2
-
3
- changelog = proc do |output, ver = nil, prev = nil|
4
- ver &&= Gem::Version.new(ver)
5
- range = [[prev], [ver, "HEAD"]].map {|ver, branch| ver ? "v#{ver.to_s}" : branch}.compact.join("..")
6
- IO.popen(%W[git log --format=fuller --topo-order --no-merges #{range}]) do |log|
7
- line = log.gets
8
- FileUtils.mkpath(File.dirname(output))
9
- File.open(output, "wb") do |f|
10
- f.print "-*- coding: utf-8 -*-\n\n", line
11
- log.each_line do |line|
12
- line.sub!(/^(?!:)(?:Author|Commit)?(?:Date)?: /, ' \&')
13
- line.sub!(/ +$/, '')
14
- f.print(line)
15
- end
16
- end
17
- end
18
- end
19
-
20
- tags = IO.popen(%w[git tag -l v[0-9]*]).grep(/v(.*)/) {$1}
21
- tags.sort_by! {|tag| tag.scan(/\d+/).map(&:to_i)}
22
- tags.inject(nil) do |prev, tag|
23
- task("logs/ChangeLog-#{tag}") {|t| changelog[t.name, tag, prev]}
24
- tag
25
- end
26
-
27
- desc "Make ChangeLog"
28
- task "ChangeLog", [:ver, :prev] do |t, ver: nil, prev: tags.last|
29
- changelog[t.name, ver, prev]
30
- end
31
-
32
- changelogs = ["ChangeLog", *tags.map {|tag| "logs/ChangeLog-#{tag}"}]
33
- task "changelogs" => changelogs
34
- CLOBBER.concat(changelogs) << "logs"
data/rakelib/epoch.rake DELETED
@@ -1,5 +0,0 @@
1
- task "build" => "date_epoch"
2
-
3
- task "date_epoch" do
4
- ENV["SOURCE_DATE_EPOCH"] = IO.popen(%W[git -C #{__dir__} log -1 --format=%ct], &:read).chomp
5
- end
data/rakelib/version.rake DELETED
@@ -1,44 +0,0 @@
1
- class << (helper = Bundler::GemHelper.instance)
2
- def update_gemspec
3
- path = gemspec.loaded_from
4
- File.open(path, "r+b") do |f|
5
- d = f.read
6
- if d.sub!(/^(_VERSION\s*=\s*)".*"/) {$1 + gemspec.version.to_s.dump}
7
- f.rewind
8
- f.truncate(0)
9
- f.print(d)
10
- end
11
- end
12
- end
13
-
14
- def commit_bump
15
- sh(%W[git -C #{__dir__} commit -m bump\ up\ to\ #{gemspec.version}
16
- #{gemspec.loaded_from}])
17
- end
18
-
19
- def version=(v)
20
- gemspec.version = v
21
- update_gemspec
22
- commit_bump
23
- end
24
- end
25
-
26
- major, minor, teeny = helper.gemspec.version.segments
27
-
28
- task "bump:teeny" do
29
- helper.version = Gem::Version.new("#{major}.#{minor}.#{teeny+1}")
30
- end
31
-
32
- task "bump:minor" do
33
- helper.version = Gem::Version.new("#{major}.#{minor+1}.0")
34
- end
35
-
36
- task "bump:major" do
37
- helper.version = Gem::Version.new("#{major+1}.0.0")
38
- end
39
-
40
- task "bump" => "bump:teeny"
41
-
42
- task "tag" do
43
- helper.__send__(:tag_version)
44
- end