class IO::Stream::Generic

def fill_read_buffer(size = @block_size)

Fills the buffer from the underlying stream.
def fill_read_buffer(size = @block_size)
	# We impose a limit because the underlying `read` system call can fail if we request too much data in one go.
	if size > @maximum_read_size
		size = @maximum_read_size
	end
	
	# This effectively ties the input and output stream together.
	flush
	
	if @read_buffer.empty?
		if sysread(size, @read_buffer)
			# Console.info(self, name: "read") {@read_buffer.inspect}
			return true
		end
	else
		if chunk = sysread(size, @input_buffer)
			@read_buffer << chunk
			# Console.info(self, name: "read") {@read_buffer.inspect}
			
			return true
		end
	end
	
	# else for both cases above:
	@eof = true
	return false
end