@JRubyMethod(optional = 1) public static IRubyObject wait_readable(ThreadContext context, IRubyObject _io, IRubyObject[] argv) { RubyIO io = (RubyIO)_io; OpenFile fptr = io.getOpenFileChecked(); fptr.checkReadable(context); long tv = prepareTimeout(context, argv); if (fptr.readPending() != 0) return context.tru; return doWait(context, io, fptr, tv, SelectionKey.OP_READ | SelectionKey.OP_ACCEPT); }
@JRubyMethod(optional = 1) public static IRubyObject wait_readable(ThreadContext context, IRubyObject _io, IRubyObject[] argv) { RubyIO io = (RubyIO)_io; OpenFile fptr = io.getOpenFileChecked(); fptr.checkReadable(context); long tv = prepareTimeout(context, argv); if (fptr.readPending() != 0) return context.tru; return doWait(context, io, fptr, tv, SelectionKey.OP_READ | SelectionKey.OP_ACCEPT); }
/** * returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil. */ @JRubyMethod(name = "ready?") public static IRubyObject ready(ThreadContext context, IRubyObject _io) { RubyIO io = (RubyIO)_io; Ruby runtime = context.runtime; OpenFile fptr; // ioctl_arg n; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); if (fptr.readPending() != 0) return runtime.getTrue(); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil; // if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil; // if (n > 0) return Qtrue; return runtime.newBoolean(fptr.readyNow(context)); }
@JRubyMethod public static IRubyObject nread(ThreadContext context, IRubyObject _io) { Ruby runtime = context.runtime; OpenFile fptr; int len; // ioctl_arg n; RubyIO io = (RubyIO)_io; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); len = fptr.readPending(); if (len > 0) return runtime.newFixnum(len); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0); // if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0); // if (n > 0) return ioctl_arg2num(n); // Because we can't get an actual system-level buffer available count, we fake it by returning 1 if ready return RubyNumeric.int2fix(runtime, fptr.readyNow(context) ? 1 : 0); }
@JRubyMethod public static IRubyObject nread(ThreadContext context, IRubyObject _io) { Ruby runtime = context.runtime; OpenFile fptr; int len; // ioctl_arg n; RubyIO io = (RubyIO)_io; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); len = fptr.readPending(); if (len > 0) return runtime.newFixnum(len); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0); // if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0); // if (n > 0) return ioctl_arg2num(n); // Because we can't get an actual system-level buffer available count, we fake it by returning 1 if ready return RubyNumeric.int2fix(runtime, fptr.readyNow(context) ? 1 : 0); }
/** * returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil. */ @JRubyMethod(name = "ready?") public static IRubyObject ready(ThreadContext context, IRubyObject _io) { RubyIO io = (RubyIO)_io; Ruby runtime = context.runtime; OpenFile fptr; // ioctl_arg n; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); if (fptr.readPending() != 0) return runtime.getTrue(); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil; // if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil; // if (n > 0) return Qtrue; return runtime.newBoolean(fptr.readyNow(context)); }
if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ && fptr.readPending() != 0) return context.tru;
if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ && fptr.readPending() != 0) return context.tru;