Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion spec/core/io/select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,17 @@
end

it "raises an ArgumentError when passed a negative timeout" do
-> { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError)
-> { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError, "time interval must not be negative")
end

ruby_version_is "4.0" do
it "raises an ArgumentError when passed negative infinity as timeout" do
-> { IO.select(nil, nil, nil, -Float::INFINITY)}.should raise_error(ArgumentError, "time interval must not be negative")
end
end

it "raises an RangeError when passed NaN as timeout" do
-> { IO.select(nil, nil, nil, Float::NAN)}.should raise_error(RangeError, "NaN out of Time range")
end

describe "returns the available descriptors when the file descriptor" do
Expand Down
2 changes: 2 additions & 0 deletions src/io_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,8 @@ Value IoObject::select(Env *env, Value read_ios, Optional<Value> write_ios, Opti
timeval timeout_tv = { 0, 0 }, *timeout_ptr = nullptr;

if (timeout && !timeout->is_nil() && !(timeout->is_float() && timeout->as_float()->is_positive_infinity())) {
if (timeout->is_float() && timeout->as_float()->is_nan())
env->raise("RangeError", "NaN out of Time range");
const auto timeout_f = timeout->to_f(env)->to_double();
if (timeout_f < 0)
env->raise("ArgumentError", "time interval must not be negative");
Expand Down
Loading