In Files

  • io/wait/lib/nonblock.rb
  • io/wait/wait.c

Parent

Class/Module Index [+]

Quicksearch

IO

Public Instance Methods

nonblock(nb = true) click to toggle source
 
               # File io/wait/lib/nonblock.rb, line 17
def nonblock(nb = true)
  nb, self.nonblock = nonblock?, nb
  yield
ensure
  self.nonblock = nb
end
            
nonblock=(nb) click to toggle source
 
               # File io/wait/lib/nonblock.rb, line 7
def nonblock=(nb)
  f = fcntl(Fcntl::F_GETFL)
  if nb
    f |= File::NONBLOCK
  else
    f &= ~File::NONBLOCK
  end
  fcntl(Fcntl::F_SETFL, f)
end
            
nonblock?() click to toggle source
 
               # File io/wait/lib/nonblock.rb, line 3
def nonblock?
  (fcntl(Fcntl::F_GETFL) & File::NONBLOCK) != 0
end
            
ready?() click to toggle source

/*

begin

 
               static VALUE
io_ready_p(io)
    VALUE io;
{
    rb_io_t *fptr;
    FILE *fp;
    ioctl_arg n;

    GetOpenFile(io, fptr);
    rb_io_check_readable(fptr);
    if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
    fp = fptr->f;
    if (feof(fp)) return Qfalse;
    if (rb_read_pending(fp)) return Qtrue;
    if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
    if (n > 0) return ioctl_arg2num(n);
    return Qnil;
}
            
wait(p1 = v1) click to toggle source

/*

begin

 
               static VALUE
io_wait(argc, argv, io)
    int argc;
    VALUE *argv;
    VALUE io;
{
    rb_io_t *fptr;
    fd_set rd;
    FILE *fp;
    int fd;
    ioctl_arg n;
    VALUE timeout;
    struct timeval *tp, timerec;

    GetOpenFile(io, fptr);
    rb_io_check_readable(fptr);
    rb_scan_args(argc, argv, "01", &timeout);
    if (NIL_P(timeout)) {
        tp = 0;
    }
    else {
        timerec = rb_time_interval(timeout);
        tp = &timerec;
    }

    fp = fptr->f;
    if (feof(fp)) return Qfalse;
    if (rb_read_pending(fp)) return Qtrue;
    fd = fileno(fp);
    FD_ZERO(&rd);
    FD_SET(fd, &rd);
    if (rb_thread_select(fd + 1, &rd, NULL, NULL, tp) < 0)
        rb_sys_fail(0);
    rb_io_check_closed(fptr);
    if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
    if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
    if (n > 0) return io;
    return Qnil;
}