We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
IO.select
1 parent e1f544c commit 698ef86Copy full SHA for 698ef86
NEWS.md
@@ -20,6 +20,11 @@ Note: We're only listing outstanding class updates.
20
Also, `Binding#local_variable_get` and `Binding#local_variable_set` reject to handle numbered parameters.
21
[[Bug #21049]]
22
23
+* IO
24
+
25
+ * `IO.select` accepts +Float::INFINITY+ as a timeout argument.
26
+ [[Feature #20610]]
27
28
* String
29
30
* Update Unicode to Version 15.1.0 and Emoji Version 15.1. [[Feature #19908]]
io.c
@@ -10993,6 +10993,16 @@ rb_io_advise(int argc, VALUE *argv, VALUE io)
10993
#endif
10994
}
10995
10996
+static int
10997
+is_pos_inf(VALUE x)
10998
+{
10999
+ double f;
11000
+ if (!RB_FLOAT_TYPE_P(x))
11001
+ return 0;
11002
+ f = RFLOAT_VALUE(x);
11003
+ return isinf(f) && 0 < f;
11004
+}
11005
11006
/*
11007
* call-seq:
11008
* IO.select(read_ios, write_ios = [], error_ios = [], timeout = nil) -> array or nil
@@ -11009,6 +11019,8 @@ rb_io_advise(int argc, VALUE *argv, VALUE io)
11009
11019
*
11010
11020
* Argument +timeout+ is a numeric value (such as integer or float) timeout
11011
11021
* interval in seconds.
11022
+ * +timeout+ can also be +nil+ or +Float::INFINITY+.
11023
+ * +nil+ and +Float::INFINITY+ means no timeout.
11012
11024
11013
11025
* The method monitors the \IO objects given in all three arrays,
11014
11026
* waiting for some to be ready;
@@ -11159,7 +11171,7 @@ rb_f_select(int argc, VALUE *argv, VALUE obj)
11159
11171
int i;
11160
11172
11161
11173
rb_scan_args(argc, argv, "13", &args.read, &args.write, &args.except, &timeout);
11162
- if (NIL_P(timeout)) {
11174
+ if (NIL_P(timeout) || is_pos_inf(timeout)) {
11163
11175
args.timeout = 0;
11164
11176
11165
11177
else {
test/ruby/test_io.rb
@@ -4262,6 +4262,23 @@ def test_select_exceptfds
4262
end
4263
end if Socket.const_defined?(:MSG_OOB)
4264
4265
+ def test_select_timeout
4266
+ assert_equal(nil, IO.select(nil,nil,nil,0))
4267
+ assert_equal(nil, IO.select(nil,nil,nil,0.0))
4268
+ assert_raise(TypeError) { IO.select(nil,nil,nil,"invalid-timeout") }
4269
+ assert_raise(ArgumentError) { IO.select(nil,nil,nil,-1) }
4270
+ assert_raise(ArgumentError) { IO.select(nil,nil,nil,-0.1) }
4271
+ assert_raise(ArgumentError) { IO.select(nil,nil,nil,-Float::INFINITY) }
4272
+ assert_raise(RangeError) { IO.select(nil,nil,nil,Float::NAN) }
4273
+ IO.pipe {|r, w|
4274
+ w << "x"
4275
+ ret = [[r], [], []]
4276
+ assert_equal(ret, IO.select([r],nil,nil,0.1))
4277
+ assert_equal(ret, IO.select([r],nil,nil,1))
4278
+ assert_equal(ret, IO.select([r],nil,nil,Float::INFINITY))
4279
+ }
4280
+ end
4281
4282
def test_recycled_fd_close
4283
dot = -'.'
4284
IO.pipe do |sig_rd, sig_wr|
0 commit comments