mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improvements to rb_io_wait
return value handling and internal implementation. (#5340)
This commit is contained in:
parent
4fccefef05
commit
acfe2f2655
Notes:
git
2021-12-24 19:11:36 +09:00
Merged-By: ioquatix <samuel@codeotaku.com>
2 changed files with 20 additions and 9 deletions
|
@ -205,7 +205,7 @@ VALUE rb_fiber_scheduler_unblock(VALUE scheduler, VALUE blocker, VALUE fiber);
|
|||
* this for instance switches to another fiber etc.
|
||||
*
|
||||
* The "events" here is a Ruby level integer, which is an OR-ed value of
|
||||
* `IO::READABLE`, `IO::WRITable`, and `IO::PRIORITY`.
|
||||
* `IO::READABLE`, `IO::WRITABLE`, and `IO::PRIORITY`.
|
||||
*
|
||||
* @param[in] scheduler Target scheduler.
|
||||
* @param[in] io An io object to wait.
|
||||
|
|
23
io.c
23
io.c
|
@ -500,7 +500,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd)
|
|||
|
||||
#if defined(_WIN32)
|
||||
#define WAIT_FD_IN_WIN32(fptr) \
|
||||
(rb_w32_io_cancelable_p((fptr)->fd) ? 0 : RB_NUM2INT(rb_io_wait(fptr->self, RB_INT2NUM(RUBY_IO_READABLE), Qnil)))
|
||||
(rb_w32_io_cancelable_p((fptr)->fd) ? Qnil : rb_io_wait(fptr->self, RB_INT2NUM(RUBY_IO_READABLE), Qnil))
|
||||
#else
|
||||
#define WAIT_FD_IN_WIN32(fptr)
|
||||
#endif
|
||||
|
@ -1323,10 +1323,9 @@ rb_io_wait(VALUE io, VALUE events, VALUE timeout)
|
|||
// Not sure if this is necessary:
|
||||
rb_io_check_closed(fptr);
|
||||
|
||||
if (ready > 0) {
|
||||
if (ready) {
|
||||
return RB_INT2NUM(ready);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Qfalse;
|
||||
}
|
||||
}
|
||||
|
@ -1490,13 +1489,25 @@ rb_io_maybe_wait(int error, VALUE io, VALUE events, VALUE timeout)
|
|||
int
|
||||
rb_io_maybe_wait_readable(int error, VALUE io, VALUE timeout)
|
||||
{
|
||||
return RB_NUM2INT(rb_io_maybe_wait(error, io, RB_INT2NUM(RUBY_IO_READABLE), timeout));
|
||||
VALUE result = rb_io_maybe_wait(error, io, RB_INT2NUM(RUBY_IO_READABLE), timeout);
|
||||
|
||||
if (RTEST(result)) {
|
||||
return RB_NUM2INT(result);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
rb_io_maybe_wait_writable(int error, VALUE io, VALUE timeout)
|
||||
{
|
||||
return RB_NUM2INT(rb_io_maybe_wait(error, io, RB_INT2NUM(RUBY_IO_WRITABLE), timeout));
|
||||
VALUE result = rb_io_maybe_wait(error, io, RB_INT2NUM(RUBY_IO_WRITABLE), timeout);
|
||||
|
||||
if (RTEST(result)) {
|
||||
return RB_NUM2INT(result);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue