Class: DRb::DRbMessage
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/drb/drb.rb |
Overview
Handler for sending and receiving drb messages.
This takes care of the low-level marshalling and unmarshalling of drb requests and responses sent over the wire between server and client. This relieves the implementor of a new drb protocol layer with having to deal with these details.
The user does not have to directly deal with this object in normal use.
Class Method Summary
- .new(config) ⇒ DRbMessage constructor Internal use only
Instance Method Summary
- #dump(obj, error = false) Internal use only
- #load(soc) Internal use only
- #recv_reply(stream) Internal use only
- #recv_request(stream) Internal use only
- #send_reply(stream, succ, result) Internal use only
- #send_request(stream, ref, msg_id, arg, b) Internal use only
- #make_proxy(obj, error = false) private Internal use only
Constructor Details
.new(config) ⇒ DRbMessage
This method is for internal use only.
Instance Method Details
#dump(obj, error = false)
This method is for internal use only.
[ GitHub ]
# File 'lib/drb/drb.rb', line 562
def dump(obj, error=false) # :nodoc: obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped begin str = Marshal::dump(obj) rescue str = Marshal::dump(make_proxy(obj, error)) end [str.size].pack('N') + str end
#load(soc)
This method is for internal use only.
# File 'lib/drb/drb.rb', line 572
def load(soc) # :nodoc: begin sz = soc.read(4) # sizeof (N) rescue raise(DRbConnError, $!., $!.backtrace) end raise(DRbConnError, 'connection closed') if sz.nil? raise(DRbConnError, 'premature header') if sz.size < 4 sz = sz.unpack('N')[0] raise(DRbConnError, "too large packet #{sz}") if @load_limit < sz begin str = soc.read(sz) rescue raise(DRbConnError, $!., $!.backtrace) end raise(DRbConnError, 'connection closed') if str.nil? raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz DRb.mutex.synchronize do begin save = Thread.current[:drb_untaint] Thread.current[:drb_untaint] = [] Marshal::load(str) rescue NameError, ArgumentError DRbUnknown.new($!, str) ensure Thread.current[:drb_untaint].each do |x| x.untaint end Thread.current[:drb_untaint] = save end end end
#make_proxy(obj, error = false) (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/drb/drb.rb', line 646
def make_proxy(obj, error=false) # :nodoc: if error DRbRemoteError.new(obj) else DRbObject.new(obj) end end
#recv_reply(stream)
This method is for internal use only.
[ GitHub ]
#recv_request(stream)
This method is for internal use only.
# File 'lib/drb/drb.rb', line 619
def recv_request(stream) # :nodoc: ref = load(stream) ro = DRb.to_obj(ref) msg = load(stream) argc = load(stream) raise(DRbConnError, "too many arguments") if @argc_limit < argc argv = Array.new(argc, nil) argc.times do |n| argv[n] = load(stream) end block = load(stream) return ro, msg, argv, block end
#send_reply(stream, succ, result)
This method is for internal use only.
[ GitHub ]
# File 'lib/drb/drb.rb', line 633
def send_reply(stream, succ, result) # :nodoc: stream.write(dump(succ) + dump(result, !succ)) rescue raise(DRbConnError, $!., $!.backtrace) end
#send_request(stream, ref, msg_id, arg, b)
This method is for internal use only.
[ GitHub ]
# File 'lib/drb/drb.rb', line 605
def send_request(stream, ref, msg_id, arg, b) # :nodoc: ary = [] ary.push(dump(ref.__drbref)) ary.push(dump(msg_id.id2name)) ary.push(dump(arg.length)) arg.each do |e| ary.push(dump(e)) end ary.push(dump(b)) stream.write(ary.join('')) rescue raise(DRbConnError, $!., $!.backtrace) end