Module: Gio::PollableInputStream

Defined in:
lib/gio2/pollable-input-stream.rb

Instance Method Summary collapse

Instance Method Details

#create_source(&block) ⇒ Object



20
21
22
23
24
25
# File 'lib/gio2/pollable-input-stream.rb', line 20

def create_source(&block)
  source = create_source_raw
  source.extend(PollableSource)
  source.set_callback(&block)
  source
end

#create_source_rawObject



19
# File 'lib/gio2/pollable-input-stream.rb', line 19

alias_method :create_source_raw, :create_source

#read_nonblocking(size = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gio2/pollable-input-stream.rb', line 28

def read_nonblocking(size=nil)
  if size.nil?
    all = "".b
    buffer_size = 8192
    buffer = " ".b * buffer_size
    loop do
      begin
        read_bytes = read_nonblocking_raw_compatible(buffer)
      rescue IOError::WouldBlock
        break
      end
      all << buffer.byteslice(0, read_bytes)
      break if read_bytes != buffer_size
    end
    all
  else
    buffer = " ".b * size
    read_bytes = read_nonblocking_raw_compatible(buffer)
    buffer.replace(buffer.byteslice(0, read_bytes))
    buffer
  end
end

#read_nonblocking_rawObject



27
# File 'lib/gio2/pollable-input-stream.rb', line 27

alias_method :read_nonblocking_raw, :read_nonblocking