}
@JRubyMethod
public static IRubyObject rbuf_fill(IRubyObject recv) {
RubyString buf = (RubyString)recv.getInstanceVariables().getInstanceVariable("@rbuf");
RubyIO io = (RubyIO)recv.getInstanceVariables().getInstanceVariable("@io");
int timeout = RubyNumeric.fix2int(recv.getInstanceVariables().getInstanceVariable("@read_timeout")) * 1000;
NativeImpl nim = (NativeImpl)recv.dataGetStruct();
Selector selector = null;
try {
selector = Selector.open();
nim.channel.configureBlocking(false);
SelectionKey key = nim.channel.register(selector, SelectionKey.OP_READ);
int n = selector.select(timeout);
if(n > 0) {
IRubyObject readItems = io.read(new IRubyObject[]{recv.getRuntime().newFixnum(1024*16)});
return buf.concat(readItems);
} else {
RubyClass exc = (RubyClass)(recv.getRuntime().getModule("Timeout").getConstant("Error"));
throw new RaiseException(RubyException.newException(recv.getRuntime(), exc, "execution expired"),false);
}