nArg = 1;
} else {
throw runtime.newNotImplementedError("JRuby does not support string for second fcntl/ioctl argument yet");
}
OpenFile myOpenFile = getOpenFileChecked();
// Fixme: Only F_SETFL and F_GETFL is current supported
// FIXME: Only NONBLOCK flag is supported
// FIXME: F_SETFL and F_SETFD are treated as the same thing here. For the case of dup(fd) we
// should actually have F_SETFL only affect one (it is unclear how well we do, but this TODO
// is here to at least document that we might need to do more work here. Mostly SETFL is
// for mode changes which should persist across fork() boundaries. Since JVM has no fork
// this is not a problem for us.
try {
if (realCmd == FcntlLibrary.FD_CLOEXEC) {
// Do nothing. FD_CLOEXEC has no meaning in JVM since we cannot really exec.
// And why the hell does webrick pass this in as a first argument!!!!!
} else if (realCmd == Fcntl.F_SETFL.value() || realCmd == Fcntl.F_SETFD.value()) {
if ((nArg & FcntlLibrary.FD_CLOEXEC) == FcntlLibrary.FD_CLOEXEC) {
// Do nothing. FD_CLOEXEC has no meaning in JVM since we cannot really exec.
} else {
boolean block = (nArg & ModeFlags.NONBLOCK) != ModeFlags.NONBLOCK;
myOpenFile.getMainStreamSafe().setBlocking(block);
}
} else if (realCmd == Fcntl.F_GETFL.value()) {
return myOpenFile.getMainStreamSafe().isBlocking() ? RubyFixnum.zero(runtime) : RubyFixnum.newFixnum(runtime, ModeFlags.NONBLOCK);
} else {
throw runtime.newNotImplementedError("JRuby only supports F_SETFL and F_GETFL with NONBLOCK for fcntl/ioctl");
}
} catch (BadDescriptorException e) {
throw runtime.newErrnoEBADFError();