Skip to content

Commit 854787a

Browse files
hsbtk0kubun
authored andcommitted
Merge io-wait 0.3.2
1 parent 282cbf6 commit 854787a

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

ext/io/wait/extconf.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
# frozen_string_literal: false
22
require 'mkmf'
33

4-
if RUBY_VERSION < "2.6"
5-
File.write("Makefile", dummy_makefile($srcdir).join(""))
4+
target = "io/wait"
5+
have_func("rb_io_wait", "ruby/io.h")
6+
have_func("rb_io_descriptor", "ruby/io.h")
7+
unless macro_defined?("DOSISH", "#include <ruby.h>")
8+
have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil
9+
fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h|
10+
have_macro("FIONREAD", [h, ioctl_h].compact)
11+
end
12+
if fionread
13+
$defs << "-DFIONREAD_HEADER=\"<#{fionread}>\""
14+
create_makefile(target)
15+
end
616
else
7-
target = "io/wait"
8-
have_func("rb_io_wait")
9-
have_func("rb_io_descriptor")
10-
unless macro_defined?("DOSISH", "#include <ruby.h>")
11-
have_header(ioctl_h = "sys/ioctl.h") or ioctl_h = nil
12-
fionread = %w[sys/ioctl.h sys/filio.h sys/socket.h].find do |h|
13-
have_macro("FIONREAD", [h, ioctl_h].compact)
14-
end
15-
if fionread
16-
$defs << "-DFIONREAD_HEADER=\"<#{fionread}>\""
17-
create_makefile(target)
18-
end
19-
else
20-
if have_func("rb_w32_ioctlsocket", "ruby.h")
21-
have_func("rb_w32_is_socket", "ruby.h")
22-
create_makefile(target)
23-
end
17+
if have_func("rb_w32_ioctlsocket", "ruby.h")
18+
have_func("rb_w32_is_socket", "ruby.h")
19+
create_makefile(target)
2420
end
2521
end

ext/io/wait/io-wait.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_VERSION = "0.3.1"
1+
_VERSION = "0.3.2"
22

33
Gem::Specification.new do |spec|
44
spec.name = "io-wait"
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
1010
spec.description = %q{Waits until IO is readable or writable without blocking.}
1111
spec.homepage = "https://github.com/ruby/io-wait"
1212
spec.licenses = ["Ruby", "BSD-2-Clause"]
13+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0")
1314

1415
spec.metadata["homepage_uri"] = spec.homepage
1516
spec.metadata["source_code_uri"] = spec.homepage

ext/io/wait/wait.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,22 @@ io_event_from_value(VALUE value)
312312
/*
313313
* call-seq:
314314
* io.wait(events, timeout) -> event mask, false or nil
315-
* io.wait(timeout = nil, mode = :read) -> self, true, or false
315+
* io.wait(*event_symbols[, timeout]) -> self, true, or false
316316
*
317317
* Waits until the IO becomes ready for the specified events and returns the
318318
* subset of events that become ready, or a falsy value when times out.
319319
*
320320
* The events can be a bit mask of +IO::READABLE+, +IO::WRITABLE+ or
321321
* +IO::PRIORITY+.
322322
*
323-
* Returns a truthy value immediately when buffered data is available.
323+
* Returns an event mask (truthy value) immediately when buffered data is
324+
* available.
324325
*
325-
* Optional parameter +mode+ is one of +:read+, +:write+, or
326-
* +:read_write+.
326+
* The second form: if one or more event symbols (+:read+, +:write+, or
327+
* +:read_write+) are passed, the event mask is the bit OR of the bitmask
328+
* corresponding to those symbols. In this form, +timeout+ is optional, the
329+
* order of the arguments is arbitrary, and returns +io+ if any of the
330+
* events is ready.
327331
*
328332
* You must require 'io/wait' to use this method.
329333
*/
@@ -360,10 +364,6 @@ io_wait(int argc, VALUE *argv, VALUE io)
360364
rb_io_event_t events = 0;
361365
int i, return_io = 0;
362366

363-
/* The documented signature for this method is actually incorrect.
364-
* A single timeout is allowed in any position, and multiple symbols can be given.
365-
* Whether this is intentional or not, I don't know, and as such I consider this to
366-
* be a legacy/slow path. */
367367
if (argc != 2 || (RB_SYMBOL_P(argv[0]) || RB_SYMBOL_P(argv[1]))) {
368368
/* We'd prefer to return the actual mask, but this form would return the io itself: */
369369
return_io = 1;

test/io/wait/test_io_wait.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def test_wait_eof
7878
ret = nil
7979
assert_nothing_raised(Timeout::Error) do
8080
q.push(true)
81-
Timeout.timeout(0.1) { ret = @r.wait }
81+
t = EnvUtil.apply_timeout_scale(0.1)
82+
Timeout.timeout(t) { ret = @r.wait }
8283
end
8384
assert_equal @r, ret
8485
ensure
@@ -113,7 +114,8 @@ def test_wait_readable_eof
113114
ret = nil
114115
assert_nothing_raised(Timeout::Error) do
115116
q.push(true)
116-
Timeout.timeout(0.1) { ret = @r.wait_readable }
117+
t = EnvUtil.apply_timeout_scale(0.1)
118+
Timeout.timeout(t) { ret = @r.wait_readable }
117119
end
118120
assert_equal @r, ret
119121
ensure

test/io/wait/test_ractor.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ def test_ractor
77
ext = "/io/wait.#{RbConfig::CONFIG['DLEXT']}"
88
path = $".find {|path| path.end_with?(ext)}
99
assert_in_out_err(%W[-r#{path}], <<-"end;", ["true"], [])
10+
class Ractor
11+
alias value take
12+
end unless Ractor.method_defined? :value # compat with Ruby 3.4 and olders
13+
1014
$VERBOSE = nil
1115
r = Ractor.new do
1216
$stdout.equal?($stdout.wait_writable)
1317
end
14-
puts r.take
18+
puts r.value
1519
end;
1620
end
1721
end if defined? Ractor

0 commit comments

Comments
 (0)