Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created March 5, 2011 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordansissel/856207 to your computer and use it in GitHub Desktop.
Save jordansissel/856207 to your computer and use it in GitHub Desktop.
IO.for_fd behaves strangely in jruby
require "rubygems"
require "ffi"
class Inotify
module CFunctions
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :inotify_init, [], :int
end
include CFunctions
def initialize
@fd = inotify_init
puts "inotify_init returned: #{@fd.inspect}"
@io = IO.for_fd(@fd)
puts "inotify_init (through IO.for_fd.fileno) returned: #{@io.fileno.inspect}"
end
end
inotify = Inotify.new
% rvm 1.8.7,1.9.2,jruby-1.5.6,jruby-1.6.0.RC2 inotify.rb
# 1.8.7
inotify_init returned: 3
inotify_init (through IO.for_fd.fileno) returned: 3
# 1.9.2
inotify_init returned: 3
inotify_init (through IO.for_fd.fileno) returned: 3
# jruby 1.5.6, crashes in IO.for_fd(8)
inotify_init returned: 8
inotify.rb:17:in `initialize': Bad file descriptor - Bad file descriptor (Errno::EBADF)
from inotify.rb:17:in `for_fd'
from inotify.rb:17:in `initialize'
from inotify.rb:22:in `new'
from inotify.rb:22
# jruby 1.6.0.RC2, IO.for_fd(5).fileno == 2? Huh?
inotify_init returned: 5
inotify_init (through IO.for_fd.fileno) returned: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment