methodmissing / eio

A libeio (http://software.schmorp.de/pkg/libeio.html) wrapper for Ruby
http://github.com/methodmissing/eio
Other
29 stars 0 forks source link

unable to do open/write #2

Open wquockATblurb opened 12 years ago

wquockATblurb commented 12 years ago

I try this

path = "/tmp/asyncdl.out"
file = nil
EM.run do
  EIO.eventmachine_handler # let libeio notify when there's result callbacks to invoke
  # file = File.new('/tmp/asyncdl.out', 'w')
  # EIO.write(file.fileno, "buf contents: hello") do |b|
  #   EIO.close(file.fileno) { EM.stop_event_loop }
  # end
  EIO.open(path, EIO::APPEND) do |fd|
    EIO.write(fd, "buf contents: hello") do |b|
      EIO.close(fd) { EM.stop_event_loop }
    end
  end
end

but got

/Library/Ruby/Gems/1.8/gems/eio-0.1/lib/eio/eventmachine.rb:13:in `poll': Bad file descriptor (Errno::EBADF)
    from /Library/Ruby/Gems/1.8/gems/eio-0.1/lib/eio/eventmachine.rb:13:in `notify_readable'
    from /Library/Ruby/Gems/1.8/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run_machine'
    from /Library/Ruby/Gems/1.8/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run'
    from asyndl-eio.rb:21
wquockATblurb commented 12 years ago

figured out. need to do

EIO.open(path, EIO::CREAT|EIO::RDWR)