@JRubyMethod(required = 1)
public IRubyObject flock(ThreadContext context, IRubyObject lockingConstant) {
// TODO: port exact behavior from MRI, and move most locking logic into ChannelDescriptor
// TODO: for all LOCK_NB cases, return false if they would block
try {
ChannelDescriptor descriptor = openFile.getMainStreamSafe().getDescriptor();
// null channel always succeeds for all locking operations
if (descriptor.isNull()) return RubyFixnum.zero(context.getRuntime());
if (descriptor.getChannel() instanceof FileChannel) {
FileChannel fileChannel = (FileChannel)descriptor.getChannel();
int lockMode = RubyNumeric.num2int(lockingConstant);
// This logic used to attempt a shared lock instead of an exclusive
// lock, because LOCK_EX on some systems (as reported in JRUBY-1214)
// allow exclusively locking a read-only file. However, the JDK