Update io_spec.c
to use rb_io_maybe_wait*
if possible. (#11792)
This commit is contained in:
parent
c878843b2c
commit
c33cb9a586
Notes:
git
2024-10-04 07:36:15 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
@ -143,7 +143,11 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
|
|||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RUBY_VERSION_IS_3_1
|
||||||
|
ret = rb_io_maybe_wait_readable(errno, io, Qnil);
|
||||||
|
#else
|
||||||
ret = rb_io_wait_readable(fd);
|
ret = rb_io_wait_readable(fd);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (RTEST(read_p)) {
|
if (RTEST(read_p)) {
|
||||||
ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF);
|
ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF);
|
||||||
@ -162,7 +166,11 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VALUE io_spec_rb_io_wait_writable(VALUE self, VALUE io) {
|
VALUE io_spec_rb_io_wait_writable(VALUE self, VALUE io) {
|
||||||
|
#ifdef RUBY_VERSION_IS_3_1
|
||||||
|
int ret = rb_io_maybe_wait_writable(errno, io, Qnil);
|
||||||
|
#else
|
||||||
int ret = rb_io_wait_writable(io_spec_get_fd(io));
|
int ret = rb_io_wait_writable(io_spec_get_fd(io));
|
||||||
|
#endif
|
||||||
return ret ? Qtrue : Qfalse;
|
return ret ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,13 +238,23 @@ VALUE io_spec_rb_thread_wait_fd(VALUE self, VALUE io) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VALUE io_spec_rb_wait_for_single_fd(VALUE self, VALUE io, VALUE events, VALUE secs, VALUE usecs) {
|
VALUE io_spec_rb_wait_for_single_fd(VALUE self, VALUE io, VALUE events, VALUE secs, VALUE usecs) {
|
||||||
int fd = io_spec_get_fd(io);
|
#ifdef RUBY_VERSION_IS_3_0
|
||||||
|
VALUE timeout = Qnil;
|
||||||
|
if (!NIL_P(secs)) {
|
||||||
|
timeout = rb_float_new((double)FIX2INT(secs) + (0.000001f * FIX2INT(usecs)));
|
||||||
|
}
|
||||||
|
VALUE result = rb_io_wait(io, events, timeout);
|
||||||
|
if (result == Qfalse) return INT2FIX(0);
|
||||||
|
else return result;
|
||||||
|
#else
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
if (!NIL_P(secs)) {
|
if (!NIL_P(secs)) {
|
||||||
tv.tv_sec = FIX2INT(secs);
|
tv.tv_sec = FIX2INT(secs);
|
||||||
tv.tv_usec = FIX2INT(usecs);
|
tv.tv_usec = FIX2INT(usecs);
|
||||||
}
|
}
|
||||||
|
int fd = io_spec_get_fd(io);
|
||||||
return INT2FIX(rb_wait_for_single_fd(fd, FIX2INT(events), NIL_P(secs) ? NULL : &tv));
|
return INT2FIX(rb_wait_for_single_fd(fd, FIX2INT(events), NIL_P(secs) ? NULL : &tv));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE io_spec_rb_thread_fd_writable(VALUE self, VALUE io) {
|
VALUE io_spec_rb_thread_fd_writable(VALUE self, VALUE io) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user