summaryrefslogtreecommitdiff
path: root/ext/io/wait/wait.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-10-23 19:41:20 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-07 09:54:35 +0900
commit3ba1580d800b4751e1944242a82d4db96864f1fe (patch)
treee1ad81842eee145096a07294b6c7b9b8014865de /ext/io/wait/wait.c
parent68d028578a5975fe6c44d29c502615ff9af72927 (diff)
[ruby/io-wait] Revise IO#wait arguments
https://github.com/ruby/io-wait/commit/0599f6d4d6 https://github.com/ruby/io-wait/commit/4e982aea1b https://github.com/ruby/io-wait/commit/5b45685eb3
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4244
Diffstat (limited to 'ext/io/wait/wait.c')
-rw-r--r--ext/io/wait/wait.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/ext/io/wait/wait.c b/ext/io/wait/wait.c
index 73bc77a294..5c1a704766 100644
--- a/ext/io/wait/wait.c
+++ b/ext/io/wait/wait.c
@@ -211,7 +211,7 @@ wait_mode_sym(VALUE mode)
/*
* call-seq:
* 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
* 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.
*
* Optional parameter +mode+ is one of +:read+, +:write+, or
- * +:read_write+ (deprecated).
+ * +:read_write+.
*/
static VALUE
io_wait(int argc, VALUE *argv, VALUE io)
{
- VALUE timeout = Qnil;
+ VALUE timeout = Qundef;
rb_io_event_t events = 0;
- if (argc < 2 || (argc >= 2 && RB_SYMBOL_P(argv[1]))) {
- if (argc > 0) {
- timeout = argv[0];
- }
-
- for (int i = 1; i < argc; i += 1) {
- events |= wait_mode_sym(argv[i]);
+ if (argc != 2 || (RB_SYMBOL_P(argv[0]) || RB_SYMBOL_P(argv[1]))) {
+ for (int i = 0; i < argc; i += 1) {
+ if (RB_SYMBOL_P(argv[i])) {
+ events |= wait_mode_sym(argv[i]);
+ }
+ else if (timeout == Qundef) {
+ 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]);
-
- if (argv[1] != Qnil) {
- timeout = argv[1];
- }
- }
- else {
- // TODO error
- return Qnil;
+ timeout = argv[1];
}
if (events == 0) {