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 = "".force_encoding("ASCII-8BIT")
buffer_size = 8192
buffer = " ".force_encoding("ASCII-8BIT") * buffer_size
loop do
begin
read_bytes = read_nonblocking_raw(buffer, buffer.bytesize)
rescue IOError::WouldBlock
break
end
all << buffer.byteslice(0, read_bytes)
break if read_bytes != buffer_size
end
all
else
buffer = " " * size
read_bytes = read_nonblocking_raw(buffer, buffer.bytesize)
buffer.replace(buffer.byteslice(0, read_bytes))
buffer
end
end
|