module Dizby::ReadableStream
Public Instance Methods
read()
click to toggle source
# File lib/dizby/stream/readable.rb, line 11 def read sz = check_packet_size(load_size) str = load_packet(sz) raise ConnectionError, 'connection closed' unless str if str.size < sz raise ConnectionError, 'premature marshal format(can\'t read)' end load_obj(str) # TODO: un-tainting??? end
Private Instance Methods
check_packet_size(sz)
click to toggle source
# File lib/dizby/stream/readable.rb, line 55 def check_packet_size(sz) raise RemoteServerShutdown unless sz raise ConnectionError, 'premature header' if sz.size < 4 sz = sz.unpack('N')[0] # load_limit must be greater than the size of the packet # or the load_limit can be 0 or less to be considered "infinite" if @server.load_limit.between?(0, sz) raise ConnectionError, "too large packet for #{sz}" end sz end
load_obj(marshalled_str)
click to toggle source
# File lib/dizby/stream/readable.rb, line 40 def load_obj(marshalled_str) @server.log.debug("loading data: #{marshalled_str.inspect}") obj = Marshal.load(marshalled_str) @server.log.debug("loaded: #{obj.inspect}") # get a local object or create the proxy using the current server # done here since marshalling doesn't know about the current server obj = obj.evaluate(@server) if obj.is_a?(SemiObjectProxy) obj rescue NameError, ArgumentError @server.log.debug("unknown: #{$!.inspect} #{$!.backtrace}") UnknownObject.new($!, marshalled_str) end
load_packet(sz)
click to toggle source
# File lib/dizby/stream/readable.rb, line 34 def load_packet(sz) @stream.read(sz) rescue raise ConnectionError, $!.message, $!.backtrace end
load_size()
click to toggle source
# File lib/dizby/stream/readable.rb, line 28 def load_size @stream.read(4) rescue raise ConnectionError, $!.message, $!.backtrace end