Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync "Rework console to use rb_io_wait." #17

Merged
merged 2 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions ext/io/console/console.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* -*- c-file-style: "ruby" -*- */
/* -*- c-file-style: "ruby"; indent-tabs-mode: t -*- */
/*
* console IO module
*/
Expand Down Expand Up @@ -80,6 +80,10 @@ static ID id_getc, id_console, id_close, id_min, id_time, id_intr;
static ID id_gets;
#endif

#ifdef HAVE_RB_SCHEDULER_TIMEOUT
extern VALUE rb_scheduler_timeout(struct timeval *timeout);
#endif

#define sys_fail_fptr(fptr) rb_sys_fail_str((fptr)->pathv)

#ifndef HAVE_RB_F_SEND
Expand Down Expand Up @@ -510,25 +514,41 @@ console_getch(int argc, VALUE *argv, VALUE io)
rb_io_t *fptr;
VALUE str;
wint_t c;
int w, len;
int len;
char buf[8];
wint_t wbuf[2];
# ifndef HAVE_RB_IO_WAIT
struct timeval *to = NULL, tv;
# else
VALUE timeout = Qnil;
# endif

GetOpenFile(io, fptr);
if (optp) {
if (optp->vtime) {
# ifndef HAVE_RB_IO_WAIT
to = &tv;
# else
struct timeval tv;
# endif
tv.tv_sec = optp->vtime / 10;
tv.tv_usec = (optp->vtime % 10) * 100000;
# ifdef HAVE_RB_IO_WAIT
timeout = rb_scheduler_timeout(&tv);
# endif
}
if (optp->vmin != 1) {
rb_warning("min option ignored");
}
if (optp->intr) {
w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
# ifndef HAVE_RB_IO_WAIT
int w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
if (w < 0) rb_eof_error();
if (!(w & RB_WAITFD_IN)) return Qnil;
# else
VALUE result = RB_NUM2INT(rb_io_wait(io, RUBY_IO_READABLE, timeout));
if (result == Qfalse) return Qnil;
# endif
}
else {
rb_warning("vtime option ignored if intr flag is unset");
Expand Down
3 changes: 3 additions & 0 deletions ext/io/console/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# rb_funcallv: 2.1.0
# RARRAY_CONST_PTR: 2.1.0
# rb_sym2str: 2.2.0
if have_func("rb_scheduler_timeout")
have_func("rb_io_wait")
end
$defs << "-D""ENABLE_IO_GETPASS=1"
create_makefile("io/console") {|conf|
conf << "\n""VK_HEADER = #{vk_header}\n"
Expand Down