Module: MemoryLimit::IO

Defined in:
lib/unicorn-cuba-base/memory_limit.rb

Instance Method Summary collapse

Instance Method Details

#read(bytes = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unicorn-cuba-base/memory_limit.rb', line 17

def read(bytes = nil)
  data = @root_limit.get("#{self.class.name} IO read") do |max_read_bytes|
    if not bytes or bytes > max_read_bytes
      data = super max_read_bytes
      raise MemoryLimitedExceededError unless eof?
      data or '' # read() always returns '' on EOF
    else
      super bytes or ''
    end
  end
end

#root_limit(ml) ⇒ Object



13
14
15
# File 'lib/unicorn-cuba-base/memory_limit.rb', line 13

def root_limit(ml)
  @root_limit = ml
end