method
wait
v1_9_2_180 -
Show latest stable
- Class:
IO
wait(p1 = v1)public
Waits until input is available or times out and returns self or nil when EOF is reached.
static VALUE
io_wait(int argc, VALUE *argv, VALUE io)
{
rb_io_t *fptr;
struct wait_readable_arg arg;
int fd, i;
ioctl_arg n;
VALUE timeout;
struct timeval timerec;
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_scan_args(argc, argv, "01", &timeout);
if (NIL_P(timeout)) {
arg.timeout = 0;
}
else {
timerec = rb_time_interval(timeout);
arg.timeout = &timerec;
}
if (rb_io_read_pending(fptr)) return Qtrue;
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
fd = fptr->fd;
rb_fd_init(&arg.fds);
rb_fd_set(fd, &arg.fds);
#ifdef HAVE_RB_FD_INIT
i = (int)rb_ensure(wait_readable, (VALUE)&arg,
(VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg.fds);
#else
i = rb_thread_select(fd + 1, rb_fd_ptr(&arg.fds), NULL, NULL, arg.timeout);
#endif
if (i < 0)
rb_sys_fail(0);
rb_io_check_closed(fptr);
if (ioctl(fptr->fd, FIONREAD, &n)) rb_sys_fail(0);
if (n > 0) return io;
return Qnil;
} Related methods
- Instance methods
- <<
- autoclose=
- autoclose?
- binmode
- binmode?
- bytes
- chars
- close
- close_on_exec=
- close_on_exec?
- close_read
- close_write
- closed?
- codepoints
- each
- each_byte
- each_char
- each_codepoint
- each_line
- eof
- eof?
- expect
- external_encoding
- fcntl
- fdatasync
- fileno
- flush
- fsync
- getbyte
- getc
- gets
- initialize_copy
- inspect
- internal_encoding
- ioctl
- isatty
- lineno
- lineno=
- lines
- nread
- pid
- pos
- pos=
- printf
- putc
- puts
- read
- read_nonblock
- readbyte
- readchar
- readline
- readlines
- readpartial
- ready?
- reopen
- rewind
- scanf
- seek
- set_encoding
- stat
- sync
- sync=
- sysread
- sysseek
- syswrite
- tell
- to_i
- to_io
- tty?
- ungetbyte
- ungetc
- wait
- write
- write_nonblock
- Class methods
- binread
- copy_stream
- for_fd
- foreach
- new
- open
- pipe
- popen
- read
- readlines
- select
- sysopen
- try_convert
- Private methods
-
block_scanf -
soak_up_spaces