Sha256: fa158f5c353a1bba7acefab2f91d20e8552679e3d7b6a91b6e3213e871954fbb

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module Ragweed
  class Device
    def initialize(path, options={})
      @path = path
      @options = options
      @h = Wrap32::create_file(@path, :flags => Wrap32::FileAttributes::OVERLAPPED|Wrap32::FileAttributes::NORMAL)
    end

    def ioctl(code, inbuf, outbuf)
      overlap(lambda do |o|
        Wrap32::device_io_control(@h, code, inbuf, outbuf, o)
      end) do |ret, count|
        outbuf[0..count]
      end  
    end
    
    def read(sz)
      overlap(lambda do |o|
        Wrap32::read_file(@h, sz, o)
      end) do |ret, count|
        ret[0..count]
      end
    end
    
    def write(buf)
      overlap(lambda do |o|
        Wrap32::write_file(@h, buf, o)
      end) do |ret, count|
        count
      end
    end 
    
    def release
      Wrap32::close_handle(@h)
      @h = nil
    end

    private

    def overlap(proc)
      o = Wrap32::Overlapped.get
      ret = proc.call(o)
      count = o.wait(@h)
      r = yield ret, count
      o.release
      ret = r if r
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
iZsh-ragweed-0.1.8 lib/ragweed/wrap32/device.rb
tduehr-ragweed-0.1.5 lib/ragweed/wrap32/device.rb
tduehr-ragweed-0.1.6 lib/ragweed/wrap32/device.rb
tduehr-ragweed-0.1.7 lib/ragweed/wrap32/device.rb