mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/io-wait] Revise IO#wait arguments
0599f6d4d6
4e982aea1b
5b45685eb3
This commit is contained in:
parent
68d028578a
commit
3ba1580d80
Notes:
git
2021-03-07 09:55:00 +09:00
1 changed files with 17 additions and 19 deletions
|
@ -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])) {
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; i += 1) {
|
|
||||||
events |= wait_mode_sym(argv[i]);
|
events |= wait_mode_sym(argv[i]);
|
||||||
}
|
}
|
||||||
}
|
else if (timeout == Qundef) {
|
||||||
else if (argc == 2) {
|
rb_time_interval(timeout = argv[i]);
|
||||||
events = RB_NUM2UINT(argv[0]);
|
|
||||||
|
|
||||||
if (argv[1] != Qnil) {
|
|
||||||
timeout = argv[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO error
|
rb_raise(rb_eArgError, "timeout given more than once");
|
||||||
return Qnil;
|
}
|
||||||
|
}
|
||||||
|
if (timeout == Qundef) timeout = Qnil;
|
||||||
|
}
|
||||||
|
else /* argc == 2 */ {
|
||||||
|
events = RB_NUM2UINT(argv[0]);
|
||||||
|
timeout = argv[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events == 0) {
|
if (events == 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue