mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Bump io-wait version to 0.2.0
This commit is contained in:
parent
4716a8e157
commit
bfed3296ec
3 changed files with 38 additions and 39 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
_VERSION = "0.2.0"
|
||||||
|
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.name = "io-wait"
|
spec.name = "io-wait"
|
||||||
spec.version = "0.1.0"
|
spec.version = _VERSION
|
||||||
spec.authors = ["Nobu Nakada"]
|
spec.authors = ["Nobu Nakada"]
|
||||||
spec.email = ["nobu@ruby-lang.org"]
|
spec.email = ["nobu@ruby-lang.org"]
|
||||||
|
|
||||||
|
@ -8,7 +10,7 @@ Gem::Specification.new do |spec|
|
||||||
spec.description = %q{Waits until IO is readable or writable without blocking.}
|
spec.description = %q{Waits until IO is readable or writable without blocking.}
|
||||||
spec.homepage = "https://github.com/ruby/io-wait"
|
spec.homepage = "https://github.com/ruby/io-wait"
|
||||||
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
||||||
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
||||||
|
|
||||||
spec.metadata["homepage_uri"] = spec.homepage
|
spec.metadata["homepage_uri"] = spec.homepage
|
||||||
spec.metadata["source_code_uri"] = spec.homepage
|
spec.metadata["source_code_uri"] = spec.homepage
|
||||||
|
@ -20,6 +22,6 @@ Gem::Specification.new do |spec|
|
||||||
end
|
end
|
||||||
spec.extensions = %w[ext/io/wait/extconf.rb]
|
spec.extensions = %w[ext/io/wait/extconf.rb]
|
||||||
spec.bindir = "exe"
|
spec.bindir = "exe"
|
||||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
spec.executables = []
|
||||||
spec.require_paths = ["lib"]
|
spec.require_paths = ["lib"]
|
||||||
end
|
end
|
||||||
|
|
|
@ -211,7 +211,7 @@ wait_mode_sym(VALUE mode)
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* io.wait(events, timeout) -> event mask or false.
|
* io.wait(events, timeout) -> event mask or false.
|
||||||
* io.wait(timeout = nil, mode = :read) -> event mask or false (deprecated)
|
* io.wait(timeout = nil, mode = :read) -> event mask or false.
|
||||||
*
|
*
|
||||||
* Waits until the IO becomes ready for the specified events and returns the
|
* Waits until the IO becomes ready for the specified events and returns the
|
||||||
* subset of events that become ready, or +false+ when times out.
|
* subset of events that become ready, or +false+ when times out.
|
||||||
|
@ -222,34 +222,32 @@ wait_mode_sym(VALUE mode)
|
||||||
* Returns +true+ immediately when buffered data is available.
|
* Returns +true+ immediately when buffered data is available.
|
||||||
*
|
*
|
||||||
* Optional parameter +mode+ is one of +:read+, +:write+, or
|
* Optional parameter +mode+ is one of +:read+, +:write+, or
|
||||||
* +:read_write+ (deprecated).
|
* +:read_write+.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
io_wait(int argc, VALUE *argv, VALUE io)
|
io_wait(int argc, VALUE *argv, VALUE io)
|
||||||
{
|
{
|
||||||
VALUE timeout = Qnil;
|
VALUE timeout = Qundef;
|
||||||
rb_io_event_t events = 0;
|
rb_io_event_t events = 0;
|
||||||
|
|
||||||
if (argc < 2 || (argc >= 2 && RB_SYMBOL_P(argv[1]))) {
|
if (argc != 2 || (RB_SYMBOL_P(argv[0]) || RB_SYMBOL_P(argv[1]))) {
|
||||||
if (argc > 0) {
|
for (int i = 0; i < argc; i += 1) {
|
||||||
timeout = argv[0];
|
if (RB_SYMBOL_P(argv[i])) {
|
||||||
}
|
events |= wait_mode_sym(argv[i]);
|
||||||
|
}
|
||||||
for (int i = 1; i < argc; i += 1) {
|
else if (timeout == Qundef) {
|
||||||
events |= wait_mode_sym(argv[i]);
|
rb_time_interval(timeout = argv[i]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_raise(rb_eArgError, "timeout given more than once");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (timeout == Qundef) timeout = Qnil;
|
||||||
}
|
}
|
||||||
else if (argc == 2) {
|
else /* argc == 2 */ {
|
||||||
events = RB_NUM2UINT(argv[0]);
|
events = RB_NUM2UINT(argv[0]);
|
||||||
|
timeout = argv[1];
|
||||||
if (argv[1] != Qnil) {
|
|
||||||
timeout = argv[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// TODO error
|
|
||||||
return Qnil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events == 0) {
|
if (events == 0) {
|
||||||
|
|
|
@ -6,15 +6,10 @@ require 'io/wait'
|
||||||
# We may optimize IO#wait_*able for non-Linux kernels in the future
|
# We may optimize IO#wait_*able for non-Linux kernels in the future
|
||||||
class TestIOWaitUncommon < Test::Unit::TestCase
|
class TestIOWaitUncommon < Test::Unit::TestCase
|
||||||
def test_tty_wait
|
def test_tty_wait
|
||||||
begin
|
check_dev('/dev/tty', mode: 'w+') do |tty|
|
||||||
tty = File.open('/dev/tty', 'w+')
|
assert_include [ nil, tty ], tty.wait_readable(0)
|
||||||
rescue Errno::ENOENT, Errno::ENXIO => e
|
assert_equal tty, tty.wait_writable(1), 'portability test'
|
||||||
skip "/dev/tty: #{e.message} (#{e.class})"
|
|
||||||
end
|
end
|
||||||
assert_include [ nil, tty ], tty.wait_readable(0)
|
|
||||||
assert_equal tty, tty.wait_writable(1), 'portability test'
|
|
||||||
ensure
|
|
||||||
tty&.close
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fifo_wait
|
def test_fifo_wait
|
||||||
|
@ -44,36 +39,40 @@ class TestIOWaitUncommon < Test::Unit::TestCase
|
||||||
|
|
||||||
# used to find portability problems because some ppoll implementations
|
# used to find portability problems because some ppoll implementations
|
||||||
# are incomplete and do not work for certain "file" types
|
# are incomplete and do not work for certain "file" types
|
||||||
def check_dev(dev, m = :wait_readable)
|
def check_dev(dev, m = :wait_readable, mode: m == :wait_readable ? 'r' : 'w', &block)
|
||||||
begin
|
begin
|
||||||
fp = File.open("/dev/#{dev}", m == :wait_readable ? 'r' : 'w')
|
fp = File.open(dev, mode)
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
return # Ignore silently
|
||||||
rescue SystemCallError => e
|
rescue SystemCallError => e
|
||||||
skip "#{dev} could not be opened #{e.message} (#{e.class})"
|
skip "#{dev} could not be opened #{e.message} (#{e.class})"
|
||||||
end
|
end
|
||||||
assert_same fp, fp.__send__(m)
|
if block
|
||||||
|
yield fp
|
||||||
|
else
|
||||||
|
assert_same fp, fp.__send__(m)
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
fp&.close
|
fp&.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_wait_readable_urandom
|
def test_wait_readable_urandom
|
||||||
check_dev 'urandom'
|
check_dev('/dev/urandom')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_wait_readable_random
|
def test_wait_readable_random
|
||||||
File.open('/dev/random') do |fp|
|
check_dev('/dev/random') do |fp|
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
fp.wait_readable(0)
|
fp.wait_readable(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue SystemCallError => e
|
|
||||||
skip "/dev/random could not be opened #{e.message} (#{e.class})"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_wait_readable_zero
|
def test_wait_readable_zero
|
||||||
check_dev 'zero'
|
check_dev('/dev/zero')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_wait_writable_null
|
def test_wait_writable_null
|
||||||
check_dev 'null', :wait_writable
|
check_dev(IO::NULL, :wait_writable)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue