Class: DRb::DRbMessage
- Inherits:
-
Object
- Object
- DRb::DRbMessage
- Defined in:
- lib/opal/drb/drb_message.rb
Instance Method Summary collapse
- #dump(obj, error = false) ⇒ Object
-
#initialize(config) ⇒ DRbMessage
constructor
A new instance of DRbMessage.
- #load(soc) ⇒ Object
- #recv_reply(stream) ⇒ Object
- #recv_request(stream) ⇒ Object
- #send_reply(stream, succ, result) ⇒ Object
- #send_request(stream, ref, msg_id, arg, b) ⇒ Object
Constructor Details
#initialize(config) ⇒ DRbMessage
Returns a new instance of DRbMessage.
3 4 5 6 7 |
# File 'lib/opal/drb/drb_message.rb', line 3 def initialize(config) config = DRb.default_config.merge(config || {}) @load_limit = config[:load_limit] @argc_limit = config[:argc_limit] end |
Instance Method Details
#dump(obj, error = false) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/opal/drb/drb_message.rb', line 9 def dump(obj, error=false) obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped begin str = Marshal::dump(obj) rescue str = Marshal::dump(make_proxy(obj, error)) end pack_n(str.size) + str end |
#load(soc) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/opal/drb/drb_message.rb', line 19 def load(soc) begin sz = soc.read(4) rescue raise(DRbConnError, $!., $!.backtrace) end raise(DRbConnError, 'connection closed') if sz.nil? raise(DRbConnError, 'premature header') if sz.size < 4 sz = unpack_n(sz)[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 Marshal::load(str) end |
#recv_reply(stream) ⇒ Object
78 79 80 81 82 |
# File 'lib/opal/drb/drb_message.rb', line 78 def recv_reply(stream) succ = load(stream) result = load(stream) [succ, result] end |
#recv_request(stream) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/opal/drb/drb_message.rb', line 58 def recv_request(stream) 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) ⇒ Object
72 73 74 75 76 |
# File 'lib/opal/drb/drb_message.rb', line 72 def send_reply(stream, succ, result) stream.write(dump(succ) + dump(result, !succ)) rescue raise(DRbConnError, $!., $!.backtrace) end |
#send_request(stream, ref, msg_id, arg, b) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/opal/drb/drb_message.rb', line 44 def send_request(stream, ref, msg_id, arg, b) ary = [] ary.push(dump(ref.__drbref)) ary.push(dump(msg_id)) 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 |