super(runtime, klass);
}
public FileDescriptorIO(Ruby runtime, IRubyObject fd) {
super(runtime, runtime.getModule("FFI").getClass(CLASS_NAME));
ModeFlags modes;
try {
modes = newModeFlags(runtime, ModeFlags.RDWR);
int fileno = RubyNumeric.fix2int(fd);
jnr.posix.FileStat stat = runtime.getPosix().fstat(fileno);
java.nio.channels.ByteChannel channel;
if (stat.isSocket()) {
channel = new jnr.enxio.channels.NativeSocketChannel(fileno);
} else if (stat.isBlockDev() || stat.isCharDev()) {
channel = new jnr.enxio.channels.NativeDeviceChannel(fileno);
} else {
channel = new FileDescriptorByteChannel(runtime, fileno);
}
openFile.setMainStream(ChannelStream.open(getRuntime(), new ChannelDescriptor(channel, modes, FileDescriptorHelper.wrap(fileno))));
openFile.setPipeStream(openFile.getMainStreamSafe());
openFile.setMode(modes.getOpenFileFlags());
openFile.getMainStreamSafe().setSync(true);
} catch (BadDescriptorException e) {
throw runtime.newErrnoEBADFError();
}
}